trigger validation and show error visibly on field (programmatically) #766
Replies: 2 comments 1 reply
-
The What you are describing is one of the reasons why having disabled submit buttons is not a best practice. Even if you had a way to do this users would not assume they can click a disabled button. I would recommend leaving the submit button clickable. If you really want it to appear disabled until fully valid, you can just add a stylistic class instead. Validation is not ever actually "triggered" it is continually evaluated and only displayed based on validation-visibility conditions (this is how it knows the validity state even when messages are not being shown). If you really want to "force" a visibility state you can add a message to the store of a given node (the date node in your case) programatically: // where `node` is the FormKitNode of the date input.
node.store.set(
createMessage({ key: 'blurred', visible: false, value: true })
) Good luck! 👍 |
Beta Was this translation helpful? Give feedback.
-
Hi, I found a workaround for your case.
With this idea you can access to the validity of the form by My FormKit version is |
Beta Was this translation helpful? Give feedback.
-
Hi!
I have a date field for which I have tried the validation-visibility rules "live", "dirty", "submit" (I didn't see any info on validation-visibility in the docs by the way) . I am disabling the submit button until the form is valid , so I can't use "submit" , and I don't want to show the error immediatly.
So I thought , if the user tries to click the disabled Submit button, I could trigger a validation on the date field and make the error appear, if there were such a function available?
But I didn't find any methods in the api that seem to fit , but I can use a ref on the form and get
myFormRef.value?.node.children
, and get the date input. It has a "store
" property with the validation rules, and such a rule has a "visible
" boolean.Is there a way to toggle this boolean programmatically maybe?
Beta Was this translation helpful? Give feedback.
All reactions