angular-ui / ui-mask

Mask on an input field so the user can only type pre-determined pattern
https://htmlpreview.github.io/?https://github.com/angular-ui/ui-mask/master/demo/index.html
MIT License
391 stars 257 forks source link

Data with ui-mask not being stored. #150

Closed DaveKfoury closed 8 years ago

DaveKfoury commented 8 years ago

Hey! I am trying to use ui-mask, and then store the data in local storage.

All the fields that I don't use ui-mask are stored, but the ones I do use, are stored as null; The fields without the mask just don't have the ui-mask and ui-mask-placeholder lines.

Am I doing anything wrong here?

Here is an example:

<label class="item item-input item-floating-label"  
                       ng-class="{ 'has-error-lr' : dadosVeiculo.placa.$dirty && dadosVeiculo.placa.$invalid, 
                                   'valid-lr' : dadosVeiculo.placa.$dirty && dadosVeiculo.placa.$valid}">
                    <span class="input-label"><strong>License Plate</strong></span>  
                    <input type="text"  
                           name="placa"
                           ng-model="dadosAIT.placa"
                           ng-minlength="7"
                           required
                           placeholder="License Plate"                           
                           ui-mask="AAA-9999"
                           ui-mask-placeholder ui-mask-placeholder-char="_">
                    <span class="form-error" ng-show="dadosVeiculo.placa.$dirty && dadosVeiculo.placa.$error.required">This field is required!</span>
                </label>

Thanks!

lukepfeiffer10 commented 8 years ago

Are you trying to store "invalid" values in local storage? For instance, a valid license plate would be ABC-1234 according to your mask. Are you trying to store a partially filled out license place, such as ABC-____?

DaveKfoury commented 8 years ago

No! I am verifying that, and only storing good data.

lukepfeiffer10 commented 8 years ago

The only thing that is slightly wrong is that you don't need the ui-mask-placeholder or the ui-mask-placeholder-char attributes but that shouldn't be affecting the local storage process. Although since I don't know what that code looks like it's impossible to be certain.

I would just look into your storage code and see what the model value for license plate is at the time of saving to local storage. Maybe you need to tweak when that occurs...