Skip to content

Creating a custom stimulus controller to hook into searchable #3737

Closed Answered by Paul-Bob
Sandilly asked this question in Help
Discussion options

You must be logged in to vote

Hi @Sandilly.

I’ve tested this, and you can achieve it like this:

# app/avo/resources/course_link.rb
class Avo::Resources::CourseLink < Avo::BaseResource
  self.stimulus_controllers = "test"

  def fields
    field :course, as: :belongs_to, searchable: true
  end
end
# test_controller.js
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static targets = ['courseBelongsToInput']

  // I'm doing this on connect for testing, please execute this logic on the select change callback
  connect() {
    this.courseBelongsToInputTarget.parentNode.parentNode.setAttribute(
      'data-search-extra-params-value',
      JSON.stringify({
        test1: 1, // ch…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Paul-Bob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants