Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to have a signal in order to know if the Form is valid or not ? #248

Open
carere opened this issue Sep 8, 2024 · 7 comments
Assignees
Labels
question Further information is requested

Comments

@carere
Copy link

carere commented Sep 8, 2024

Hello, thx for this nice lib :)

I wonder if there is a way to get a signal which returns a boolean and is updated when the form is valid or not ?

@fabian-hiller
Copy link
Owner

We have the .invalid signal property of the form store: https://modularforms.dev/solid/api/FormStore

@ael-imra
Copy link

@fabian-hiller is there a possible way to change default value of .invalid to be true at first ? cause it doesn't change until the form get submitted

@fabian-hiller
Copy link
Owner

The idea then was to call it invalid instead of valid and only set it to true when we know for sure that the form is invalid. What is your use case? Often it is possible to combine dirty, submitted and invalid to achieve a certain goal.

@fabian-hiller fabian-hiller self-assigned this Oct 30, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Oct 30, 2024
@ael-imra
Copy link

I trying to make submit button disabled until the form is valid, here's my button component

export const FormButton: FormButtonT = (props) => {
	const [form, elemntProps] = splitProps(props, ['of'])
	return <Button {...elemntProps} disabled={form.of.invalid || !form.of.dirty} loading={form.of.submitting || elemntProps.loading} />
}

I tried to use dirty but after first input changed the button get enabled.
Example in stackblitz

@fabian-hiller
Copy link
Owner

Try to set validateOn to 'input' or 'change' in your form options when calling createForm or createFormStore. https://modularforms.dev/solid/api/FormOptions

@ael-imra
Copy link

Already did, when start typing invalid return true but after finish changing input with a valid value the invalid return false again.

@fabian-hiller
Copy link
Owner

True. Sorry for my last comment. It seems like the only way to do this at the moment is to call validate(...) initially, use form.invalid to disable the submit button and only show the error messages of an individual field if it has been touched or is dirty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants