Switch Disabled-Attribute based of the value of another input-field #741
-
Hi :), we want to set the disabled attribute to false if the startDate-value is empty and to true if the starDate-value is not empty. We set the state for the disabled-attribute with the default-value "true" and added a handler function that sets the state to the opposite if the startDate is picked. Unfortunately if we delete the startDate the endDate should be disabled again and that doesn't work and we don't know why! we already googled and tried some different events like onClick, onChange, onEmptied, onTextInput but nothing works. Do you have any idea how to change the handler function and/or which event we should use?
Thanks in advance and we are looking forward your feedback! 💚 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hey @Pia-Lueling |
Beta Was this translation helpful? Give feedback.
-
Hey @Pia-Lueling ^^ Your function handleDisabled(event) {
setIsDisabled(!event.target.value);
} This way, is the date is set, (by the way, I would call the state |
Beta Was this translation helpful? Give feedback.
-
I'll try it without PR - so this is more of a wild guess. 😁 I guess the problem is with your When you use Here is a suggestion which checks the value of the startDate input whenever there's a change. If the input is empty, isDisabled is set to function handleDisabled(event) {
const startDateValue = event.target.value;
if (startDateValue === "") {
setIsDisabled(true);
} else {
setIsDisabled(false);
}
} Feel free to try this approach and give me some frog feedback 🐸 |
Beta Was this translation helpful? Give feedback.
Hey @Pia-Lueling ^^
Your
handleDisabled
is not checking whether the date is set or not! You could for instance:This way, is the date is set,
disabled
will be false, and the opposite otherwise. Let us know if it works!(by the way, I would call the state
[endDateDisabled, setEndDateDisabled]
)