Skip to content

Commit

Permalink
Merge pull request #272 from zvaraondrej/using-model-value
Browse files Browse the repository at this point in the history
Updating Q&A with use-view-value="false" desc and example
  • Loading branch information
Huei Tan authored Jan 20, 2017
2 parents 73a8fae + 1999e7e commit ac7d9a6
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 ac7d9a6

Please sign in to comment.