1.0.12 • Published 1 year ago

esc-validation v1.0.12

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Validation Library

FormStructure

  • name : string name of the field
  • id : string optional if it's not provided name is used for id
  • value : value of the field
  • label : label of the field
  • type : type of the field. it can be of them :
    • text :
    • number:
    • date:
  • validations: array validations as array which contains
    • type : validation type (See validation types)
    • text : validation message
    • value : validation rule depending on the validation type
  • isVisited : boolean indicated if a field is visited or not. If you merge data this field will be automatically added
  • isDirty : boolean indicated if a field is visited or not. If you merge data this field will be automatically added
  • isValid : boolean indicated if a field is visited or not. If you merge data this field will be automatically added
  • messages : array string array

Validation Rules

Structure

  • type : Validation rule type. See below list for different types
  • text : Validation message. This message will be sent if field doesn't match the validation criteria
  • value: Validation rule criteria / details. It can be various different strings depending on the validation type

Rules

type : required

It checks if any value is entered to the field and invalid. No value is needed for this rule

type : min

This rule acts different based on form field type.

  • if the field data type is date : rule value can be in two different format
    • fix YYYY-MM-DD format. In this case minimum field value must be later than this date
    • variable Number,Unit,before/after format. ie : 3,M,before means 3 month earlier than today is the minimum date otherwise it's invalid.

      Unit List : | Date | Unit | | ---- | ---- | | years | y | | quarters | Q | | months | M | | weeks | w | | days | d | | hours | h | | minutes | m | | seconds | s | | milliseconds | ms |

Sample validation object

const fields = [
        {
            name:"testName1",
            label:"Test Name",
            type:"text",
            value:"12",
            isVisited:true,
            validations:[
                {
                type:"min",
                value:"3",
                text:"min 3"
                }
            ]
        },
        {
            name:"testName2",
            label:"Test Name",
            type:"text",
            value:"123456",
            isVisited:true,
            validations:[
                {
                    type:"pattern",
                    value:"123ab",
                    text:"pattern"
                },
                {
                    type:"max",
                    value:"5",
                    text:"max 5"
                },
                {
                    type:"cross-same",
                    value:"testName1",
                    text:"cross"
                }
            ]
        },
        {
            name:"testName3",
            label:"Test Name 3",
            type:"text",
            value:"1245",
            isVisited:true,
            validations:[
                {
                type:"min",
                value:"3",
                text:"min 3"
                }
            ]
        },
    ]
1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago