Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Added step, min & max to the input template #6

Closed
wants to merge 1 commit into from

Conversation

seangwright
Copy link

The templateOptions object for input type can have the properties step, min and max for when the type of the input, also specified in the templateOptions, is 'number'.

The `templateOptions` object for input type can have the properties `step`, `min` and `max` for when the type of the input, also specified in the `templateOptions`, is 'number'.
@seangwright seangwright mentioned this pull request Dec 28, 2015
6 tasks
@kamilkisiela
Copy link
Collaborator

@sgwatgit, thank you for your contribution!

I could merge your pr but I think adding attributes with not always defined values is not a great idea. Also, these attributes would be available on all types of input, not just 'number' (correct me if I'm wrong).

There is always good idea to use apiCheck, it provides consistency.

You can look at this commit to see what I mean by that: 11c2c54

@seangwright
Copy link
Author

@kamilkisiela Thanks for adding these properties in that commit.

I was not very familiar with the usage of ApiCheck until you mentioned it - then I went to looked at the repo for it and your commit and I agree that is a much better implementation.

@kamilkisiela
Copy link
Collaborator

@sgwatgit, if you have any other request feel free to submit an issue with description. This proposal for adding support for min, max and step attributes was excellent! It was definitely needed. Thanks for that!

@seangwright
Copy link
Author

@kamilkisiela When i use the latest build with these updates I am receiving warnings from ApiCheck in my console.

angular-formly: formly-field type input for property templateOptions apiCheck failed! `step`
at `Argument 1/value` must be `oneOf["number"]` 
https://github.com/formly-js/angular-formly/blob/7.3.9/other/ERRORS_AND_WARNINGS.md#formly-field-type-apicheck-failed

You passed:
{
  "type": "number",
  "label": "Economic Variable - Dollar Amount",
  "step": 0.01
}

With the types:
{
  "type": "string",
  "label": "string",
  "step": "number"
}

The API calls for:
{
  "__apiCheckData": {
    "strict": false,
    "optional": false,
    "type": "shape"
  },
  "shape": {
    "step": {
      "__apiCheckData": {
        "optional": true,
        "type": "ifNot",
        "description": "specified only if type is also specified",
        "error": "THIS IS THE PROBLEM: `step` must be `oneOf[\"number\"]`"
      },
      "ifNot": {
        "__apiCheckData": {
          "optional": false,
          "type": "enum"
        },
        "enum": [
          "number"
        ]
      }
    }
  }
}

And here is my field definition

{
    key: 'economicCalculationVars[0]',
    type: 'input',
    templateOptions: {
        type: 'number',
        label: 'Economic Variable - Dollar Amount',
        step: .01
    },
    hideExpression: 'model.economicCalculationType.id != 1',
    expressionProperties: {
        'templateOptions.required': 'model.economicCalculationType.id == 1'
    },
    validators: {
        range: function($viewValue, $modelValue, scope) {
            return $viewValue > 0;
        }
    }
}

I have tried setting step to .01, 0.01, '0.01' and 1 - none of these work. The steps are working correctly on the input fields however.

Is my field incorrectly defined or is there an issue with the field type: 'input'?

@seangwright seangwright deleted the patch-1 branch December 29, 2015 21:39
@kamilkisiela
Copy link
Collaborator

@sgwatgit Thanks for pointing this. The apiChecking is not properly set. It's my fault. I'm going to fix it soon and release new version.

@kamilkisiela
Copy link
Collaborator

@sgwatgit At the moment it is impossible to check if min, max or step are being
used only when type === 'number'. So I leave it.

I'm only checking if:
templateOptions.step is a number (optional)
templateOptions.type is a string (default: text)

@seangwright
Copy link
Author

@kamilkisiela That's fine by me. Those attributes simply won't do anything if type === 'text' so I'm not too worried about it. Everything else looks great - thanks for all the work on this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants