Skip to content

Commit

Permalink
Updating Q&A with use-view-value="false" example
Browse files Browse the repository at this point in the history
  • Loading branch information
zvaraondrej committed Jan 20, 2017
1 parent c538ea9 commit 1999e7e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Q&A.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ Add checkValid and submit into both ng-click and ng-submit
</form>
```

###Can I validate $modelValue instead of a $viewValue?###

Yes, adding `use-view-value="false"` attribute forces to use $modelValue instead of a $viewValue for evaluation when form is submitted. By default $viewValue is used. This need raises from a need of localized number inputs, which have to be stored in a $viewValue as a string (e.g. "2 000,0"), however in a $modelValue they are stored as a properly formatted number (2000). This can be done e.g. by using a custom directive with properly specified $formatters and $parsers.

```html
<div class="checkbox">
<label for="my-localized-input">
<input id="my-localized-input"
type="text"
name="myLocalizedInput"
ng-model="model.num"
my-localization-directive
validator="required"
use-view-value="false"/>
</label>
</div>
```

0 comments on commit 1999e7e

Please sign in to comment.