formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

Add 'step' attribute to templateOptions #592

Closed bialad closed 8 years ago

bialad commented 8 years ago

Hi

I'm new to both angular-formly and github, so I'm sorry if I'm doing anything wrong here. I have a issue that to me seems very strange, and I haven't been able to find a solution to it online.

The problem I had was with setting a step-attribute on a input with the type "number". Without the step-attribute my browsers won't allow my to save any decimal numbers.

My solution to this problem was to add 'step' to the "attributeOnly" property in the "getBuiltInAttributes"function. Like this:

var attributeOnly = ['placeholder', 'min', 'max', 'tabindex', 'type', 'step'];

Now I'm able to write this:

          {
                key: 'Share',
                type: 'input',
                templateOptions: {
                    label: 'Share (%)',
                    type: 'number',
                    step: 'any'
                }
           }

and get the step="any" attribute in my input.

Is this the correct way to do it?

kentcdodds commented 8 years ago

That's one way to do it. I'd welcome a PR to add that :-)

bialad commented 8 years ago

Nice, happy to contribute. :)

I however have some thought about what's best here... Since I think the step-attribute is included in the html 5 validation, the best must be to add this to the correct property. And this is where my knowledge falters.

I tried adding it to the bothAttributeAndBound-property, but can't see any difference.

SteveShaffer commented 8 years ago

I think it belongs where you have it, in the attributeOnly group since I don't think Angular pays attention to it. There's no ng-step specified in the Angular docs.

kentcdodds commented 8 years ago

Sorry it took so long to get back! It'll be in attributeOnly because (as @SteveShaffer mentioned) there is no angular equivalent (like ng-step).

koraybalci commented 8 years ago

@bialad are you planning to create a pull request for it? I am looking fwd to the step option just as you suggested.

bialad commented 8 years ago

Hi

I haven't done this before, and don't have time to get into it at the moment. (I'm on a skiing holiday) You're welcome to make the change if you want to.

Tobias

2016-01-15 4:34 GMT+01:00 Koray Balcı notifications@github.com:

@bialad https://github.com/bialad are you planning to create a pull request for it? I am looking fwd to the step option just as you suggested.

— Reply to this email directly or view it on GitHub https://github.com/formly-js/angular-formly/issues/592#issuecomment-171864079 .