colinaut / alpinejs-plugin-simple-validate

Simple Alpine form validation plugin
105 stars 5 forks source link

Plugin not supports multiple error messages? #11

Open g-rodigy opened 1 year ago

g-rodigy commented 1 year ago

For example when use derictive x-validate.required.tel, error message always the same e.g. phone required.

colinaut commented 1 year ago

As it explains in the README, the plugin creates an automatic error message but you can create your own custom error message one of three ways:

NOTE: the automatic error message is based on the name of the input — if it is named "phone" then it will automatically add "phone required" if the input name is "work-phone" than it will write "work phone required" as it converts dashes and underlines to spaces.

g-rodigy commented 1 year ago

Thanks, I read the README and looked at the code a bit, so I decided to clarify. It still will be one message for any error. I mean when input empty it's field required, when wrong value e.g. field is incorrect.

colinaut commented 1 year ago

Ah yeah sorry I didn't get your meaning initially. Yeah the plug does not have that functionality currently. It's currently a simple boolean, either the validation passes or it doesn't. I'd need to make the validation have multiple states to make it work like this. I'll reopen this and label it as an enhancement request. I'll look into how feasible that would be to add.

colinaut commented 1 year ago

@g-rodigy In the mean time, you can get this to work with the following AlpineJS code which will switch the error msg text based on the value:

<input type="tel" name="phone" value="" required />
<div
    class="error-msg"
    x-text="($validate.value('phone') === '') ? 'field required' : 'valid phone number required' "
>
    field required
</div>