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

Using two validators at the same time #4246

Closed
2 of 5 tasks
r1zaac opened this issue May 9, 2023 · 1 comment
Closed
2 of 5 tasks

Using two validators at the same time #4246

r1zaac opened this issue May 9, 2023 · 1 comment

Comments

@r1zaac
Copy link

r1zaac commented May 9, 2023

What happened?

Can we use both required and required_if at the same time?

I am trying to validate two select lists at the same time connected to each other as well. The situation/scenario is as follows:

At start, the second select list is disabled. When you choose an option from the first select list, it (the second list) becomes active. Now after choosing an option from the second list and submitting the form I am getting the error "The Error Type field is required" in fact that the field is already been filled.

I am trying to put two rules in the second select list with both "required" and "required_if" validators. (though "required_if" validator is working fine)

The code is as following:

<!-- Starting of Select List 1-->

<b-form-group>
    <validation-provider
     #default="{ errors }"
     name="Department"
     rules="oneOf:1,2|required"
    >
     <label>Department</label>
     <b-form-select
      v-model="dep"
      :options="departments"
      :state="errors.length > 0 ? false : null"
     />
     <t-error-message :errors="errors" />
    </validation-provider>
   </b-form-group>


<!--Starting of Select List 2 -->

   <b-form-group>
    <validation-provider
     #default="{ errors }"
     name="Error Type"
     rules="required_if:!dep=null|required"
    >
     <label>Error Type</label>
     <b-form-select
      v-model="selected"
      :options="bugTypes"
      :state="errors.length > 0 ? false : null"
      :disabled="dep === null"
     />
     <t-error-message :errors="errors" />
    </validation-provider>
   </b-form-group>

Here is the script:

<script>
import { required, required_if, oneOf } from '@validations'

export default {
 data() {
  return {
   required,
   required_if,
   oneOf,
   dep: null,
   selected: null,
 departments: [
    { text: 'Please Select One', disabled: true },
    { value: 1, text: 'Finance' },
    { value: 2, text: 'Operations' }
   ],
   bugTypes: [
    { text: 'Please Select One', disabled: true },
    { text: 'Error Type 1' }
   ]
   }
 }
}
</script>

How can I overcome with this problem? I would appreciate any help.

Reproduction steps

No response

Version

Vue.js 2.x and vee-validate 3.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No console erros

Demo link

Sorry no links (Gov project. Hope you understand)

Code of Conduct

@r1zaac
Copy link
Author

r1zaac commented May 9, 2023

fix: Made a blunder. Trying to pass Error Type 1 without the value . Adding a string value to it solved the problem.

bugTypes: [
    { text: 'Please Select One', disabled: true },
    { value: 'a', text: 'Error Type 1' }
   ]

@r1zaac r1zaac closed this as completed May 9, 2023
zleight1 pushed a commit to zleight1/vee-validate that referenced this issue May 29, 2024
logaretm pushed a commit that referenced this issue May 29, 2024
* feat(i18n): allow custom interpolation options for i18n

Allow for specifying custom interpolation options for i18n.
This is useful for custom interpolation patterns, such as `{{` and `}}`.
Tests added, and scoped to the i18n module.

Closes #4726

* test(i18n): undo describe scoping

Unwrapped the tests from the describe blocks, so the diff is cleaner.
Prefixed new tests names so they don't collide, also in commented section with begin/end.

#4726

* docs(i18n): add docs for interpolation settings

#4726

* docs(i18n): fix example

#4246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant