adopted-ember-addons / adopted-ember-addons/ember-cp-validations

set 'didValidate' true only for selected fields

Open
#553 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
439
Forks
172
PR merge metrics
No merged PRs in 30d

Description

### Environment

- Ember Version: 2.0
- Ember CLI Version: 2.13.0
- Ember CP Validations Version: 3.4.0

### Steps to Reproduce
**hbs:**
```


Email:
{{validated-input model=this placeholder="Enter new email" valuePath='new_email' id="new_email" didValidate=didValidate}}
Password:
{{validated-input model=this placeholder="Enter current password" valuePath='current_password' id="current_password" didValidate=didValidate}}
Submit


Confirmation Token:
{{validated-input model=this placeholder="Enter confirmation token" valuePath='confirmation_token' id="confirmation_token" didValidate=didValidate}}
Verify

```
**js:**
```
import Ember from 'ember';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
new_email: [
validator('presence', true),
validator('format', { type: 'email' })
],
current_password: [
validator('presence', true)
],
confirmation_token: [
validator('presence', true),
]
});

export default Ember.Component.extend(Validations, {
changeEmail: function() {
this.validate().then(() => {
if (this.get('validations.attrs.new_email.isValid') && this.get('validations.attrs.current_password.isValid')) {
...
....
} else {
this.set('didValidate', true);
}
});
});
```

Now when I click submit, **changeEmail** action is called and if validation fails it sets **this.set('didValidate', true);** which enables all the **three validated-input** field and shows validation error for even **confirmation_token** field. But i need to show validation error message only for **current_password** and **new_email**. vice versa when **verify** action is called

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.