0

My form has a name input and an alias input. They are in a Primevue Form inside a FormField and both have a resolver that checks for required input.

When a name is entered in the name field the value is being copied by the program to the alias field. In this case the alias resolver isn't being called and the alias field shows an error 'required' message.

When entering a value manually in the input the resolver is being called and the 'required' message appears or disappears depending on alias having a value or not.

Question is when setting values programmatically how can I trigger the validation to be performed that is set on the respective FormFields?

1 Answer 1

0

Found a way to trigger Primevue FormField validation after setting the input value programmatically.

Give the FormField a ref property:

<FormField ref="alias"

In the code where you set the value of the alias field you can now reference the internal state values of the input. These need to be changed to trigger validation.

 $_setAlias() {
            this.record.alias = this.record.name;                   // Set alias equal to the name of the record
            this.$refs.news.field.states.dirty = true;              // Set some internal status fields
            this.$refs.alias.field.states.touched = true;            
            this.$refs.alias.field.states.pristine = false;          
            this.$refs.alias.field.states.value = this.record.title; // Set internal field value.
        },

With these settings field validation is triggered. Haven't figured out if setting only some of these values works as well. That needs further investigation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.