Skip to content

Use step attribute = precision in float inputfield if html5 number #191

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

Closed

Conversation

pine3ree
Copy link
Contributor

When using FieldtypeFloat its input fields should have a step attribute matching the field precision. This still allows any number of decimals, only change the step from the default "1" to the more related "precision" value. Since the decimal fieldtype already supported it, the code was moved to the float inputfield when rendering the html attributes and applied only when a positive precision is set.

pine3ree added 2 commits May 23, 2021 14:40
Signed-off-by: pine3ree <pine3ree@gmail.com>
Signed-off-by: pine3ree <pine3ree@gmail.com>
@ryancramerdesign
Copy link
Member

@pine3ree Thanks, I will add this. One question though: it looks like it adds the step attribute regardless of whether the inputType is 'number' or 'text'. Shouldn't the "step" attribute be omitted if the inputType is text? If you agree, don't worry about updating the PR as I can add that myself, but just wanted to double check in case the omission was intentional?

@ryancramerdesign ryancramerdesign added the in-progress This PR is currently in progress and being added to the core. label Jun 1, 2021
@pine3ree
Copy link
Contributor Author

pine3ree commented Jun 1, 2021

Hello @ryancramerdesign ,

in getAttributesString the 1st line checks for it:

if($attributes && $attributes['type'] === 'number') { 

so the step attribute is added only when the attribute 'type' is 'number'
kind regards

(PS. edited)
...so the step attribute is only added on-the-fly when generating and rendering the html-attributes..

@ryancramerdesign
Copy link
Member

@pine3ree Okay thanks I understand now (that context wasn't visible on the 'Files changed' tab here).

One other question, it seems like the if(!isset($attributes['step'])) line could never resolve true, since the step attribute has a default value of any, established in InputfieldFloat::init() ? I think I can correct that by changing it to this, below but wanted to make sure I'm not missing something or breaking something you intended?

if(empty($attributes['step']) || $attributes['step'] === 'any') { 

@pine3ree
Copy link
Contributor Author

pine3ree commented Jun 1, 2021

Hello @ryancramerdesign ,

yes, correct, sorry, I had added that to my current project and forgot to add it back to my gh-fork. The purpose is obviously to add a default step based on precision, if not set programmatically (e.g. $myInputField->attr('step', '0.05').

ryancramerdesign pushed a commit that referenced this pull request Jun 1, 2021
@ryancramerdesign
Copy link
Member

Thanks @pine3ree I have added this.

@ryancramerdesign ryancramerdesign added completed PR has been successfully added and this may be closed when ready. and removed in-progress This PR is currently in progress and being added to the core. labels Jun 1, 2021
@matjazpotocnik
Copy link
Contributor

@pine3ree can you close this PR?

@pine3ree pine3ree closed this Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed PR has been successfully added and this may be closed when ready.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants