Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable number fields #167

Closed
hutzelknecht opened this issue Oct 8, 2015 · 6 comments
Closed

Enable number fields #167

hutzelknecht opened this issue Oct 8, 2015 · 6 comments

Comments

@hutzelknecht
Copy link

Hi Brian,

i would like to use text fields with type="number", but i would also need to set step="any" and maybe other attribute such as min-value to the input field in order to prevent browser validation for decimals.
image

Something like this:

<text-field type="number" step="any" attribute="amount" min="0" class="col-sm-6"/>

Of course this would be possible by introducing a numberField directive, but it would also be possible by adding a config object with numberField specific attributes and adding them to the textField template:

{
    step: "any",
    min: 0,
    max: 10
}
@hutzelknecht
Copy link
Author

actually, what about a property called "inputAttributes", that would pass on any attributes to the input field.

<text-field type="number" input-attributes="{ step: '0.1' , min: '0'}" attribute="amount"></text-field>

and in the input template have the following:

ng-attr-step="{{ $eval(attributes.inputAttributes).step }}"
ng-attr-min="{{ $eval(attributes.inputAttributes).min  }}"
ng-attr-max="{{ $eval(attributes.inputAttributes).max  }}"

of course having a scoped variable would help avoid the ugly $eval expression

@bvaughn
Copy link
Owner

bvaughn commented Oct 12, 2015

Interesting request.

One of formFor's main initial inspirations was the idea of separating the validation rules (min/max, etc) from the view rules. That being said there are clearly some cases where I'm not doing this (input type for example). Hm.

Would you be willing to create a pull request for this? I don't have much extra time lately for feature requests but I would be happy to accept a PR.

@hutzelknecht
Copy link
Author

I see your point! So tampering with the input field should more or less be through setting validation rules. My suggestion above would mean having validation rules in two separate places - which may of course be confusing.
I will file a pull request for this and have a think about a more sophisticated approach later ;-)

@bvaughn
Copy link
Owner

bvaughn commented Oct 12, 2015

Exactly. Inputs can already be validated as numeric (validation type: number or type: integer), with min/max values (validation minimum and maximum).

That being said, I don't think your idea is bad or anything either. It's just a little bit against the spirit of the library currently.

@bvaughn
Copy link
Owner

bvaughn commented Oct 31, 2015

Hey @hutzelknecht. Now that I'm back from traveling and have given this some thought, I feel a solution that's more in the spirit of this library would have to involve the validation rules themselves (else we risk the 2 being out of sync). So what I've done is this: for numeric inputs, if the validation rules contain a minimum or maximum value, this will automatically get passed along to the inner <input>.

I realize this does not cover step size. That's mostly because I can't think of a way to specify this as a validation rule. Actually I went ahead and added support for this as well, in the same manner as above.

@bvaughn
Copy link
Owner

bvaughn commented Oct 31, 2015

FYI this feature is available in the new 4.1.7 release.

@bvaughn bvaughn closed this as completed Oct 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants