johannesjo / ng-fab-form

Convenient forms for Angular with no extra markup? Fabulous!
https://johannesjo.github.io/ng-fab-form
MIT License
172 stars 25 forks source link

ng-maxlength without required #52

Closed philipkueng closed 9 years ago

philipkueng commented 9 years ago

Is there a way I can check the maxlength of a string without attaching the required tag?

johannesjo commented 9 years ago

You can edit the validations template to do so:

<div ng-messages="field.$error"
     class="validation"
     ng-show="attrs.required==''|| attrs.required">

Just remove the ng-show condition here.

philipkueng commented 9 years ago

Thanks alot!

Edit: I've created my own template and implemented it succesfully. After that I created a new div, like you posted above, and added the ng-maxlength list-item like this:

<div ng-messages="field.$error"
     class="validation">
    <ul class="list-unstyled validation-errors"
        ng-show="field.$invalid && (field.$touched || field.$dirty || form.$triedSubmit)">
        <li ng-message="maxlength">Please do not exceed {{ attrs.maxlength }} characters</li>
    </ul>
</div>

After that I implemented the form like this:

<div class="form-group">
                    <label class="control-label">
                        xyz
                    </label>
                    <input type="text"
                           class="form-control text-right"
                           placeholder="xyz"
                           ng-model="xyz"
                           input-decimal 
                           ng-maxlength="50"/> 
</div>

Seems not to work. What am I doing wrong?

johannesjo commented 9 years ago

Hm weird. That should work. I assume your input is wrapped into a form? I also wonder what input-decimal does. Does it work without. And if so, what happens if you use maxlength instead of ng-maxlength?

johannesjo commented 9 years ago

ping @devphil0 .

philipkueng commented 9 years ago

As you're assuming, I wrapped the input into a form. The directive input-decimal allows decimal numbers only.

I'm using the html-attribute maxlength as solution - you can close this issue. Thanks for your deployment.