Skip to content

Disable the belongs to input from the a polymorphic field #3726

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

You must be logged in to vote

@Sandilly, I experimented with this approach and successfully implemented the desired use case using a MutationObserver.

Please try integrating this code snippet into the stimulus controller associated with your resource and let me know how it goes.

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  async connect() {
    new MutationObserver(() => {
      // Modify this query selector ('#review_reviewable_id') to correspond to the id of your select from the polymorphic field
      const selectElement = document.querySelector('#review_reviewable_id')

      if (selectElement) {
        selectElement.disabled = true
      }
    }).observe(document.body

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Sandilly
Comment options

@Sandilly
Comment options

@Paul-Bob
Comment options

@Paul-Bob
Comment options

Answer selected by Paul-Bob
@Sandilly
Comment options

@Paul-Bob
Comment options

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