Open rctneil opened 1 week ago
Hey @rctneil.
I haven't had a very good look at the code. It's too much to take in my head. If you create a reproduction repository, I'll happily have a look.
How do we know which element to disable / enable? Is it the wrapper, the input? Both? Any others i've missed? Which?
It's the input. That's what's disabled.
In the case of the date input, there are appears to be 3 inputs. The first two have marriagedateDateInput targets assigned, the last one doesn't. Hence my use of nextElementSibling.
Your observation is correct. Avo uses a few inputs for one field. It's how the flatpickr
plugin works.
I don't know by heart how to do that with flatpickr, but maybe this thread might help.
Maybe have an "Integration with Stimulus" section of each field type docs page to explain how to deal with it specifically.
I'd love to provide that but that we would need a team at least double in size to be able to keep shipping so much. We will take a PR from good folks who can help. The docs are open source.
Again, I haven't had a very good look over the code as it's too much to load in my memory. I will have a look over your reproduction repo and try to help.
Hi,
I have a PersonResource with four fields: Type (Select), Marriage Date (Date), Marriage Date Parts (Select), and Divorced (Boolean).
I want to disable / enable the two marriage fields and the divorced field based on the value of the Type field. They should be enabled if the Type is "Spouse", and disabled if not.
I have set up Stimulus and have created a PersonResource controller.
This is what I have so far:
A few questions:
marriagedateDateInput
targets assigned, the last one doesn't. Hence my use ofnextElementSibling
.When testing this, the 3 fields do enable when changing to "Spouse", if i fill them in and save the record, those values do not save.
If I wish to change a "Spouse" back to a regular "Person", When changing the "Type" back to "Person", the fields do disable, but the values remain and don't get emptied when saving the record.
I have read through the documentation and it was very useful for setting up the Stimulus integration, but I was a bit confused with how to use stimulus to do things like toggling, enabling / disabling, etc, and interacting with different field types. A bit more on the docs would be super useful.
Maybe have an "Integration with Stimulus" section of each field type docs page to explain how to deal with it specifically.
I hope this is a lot clearer than my hectic and quick post in Discord yesterday!
Thanks!