0.2.4 • Published 6 years ago

react-native-formly-templates-md v0.2.4

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

React-native-formly: Material Template

Getting Started

Prerequisites

This is a material template for react-native-formly. So make sure that it is installed first.

Installing

npm install react-native-formly-templates-md --save

Components

input

templateOptions Configuration:

namedescriptiontypedefault
labelInput Labelstring-
placeholderInput placeholderstring-
descriptionInput descriptionstring-
requiredInput should have a valuebool-
disabledInput is disabledbool-
minlengthMinimum character length to be enterednumber-
maxlengthMaximum character length to be enterednumber-
typeInput text typestring of (text, number, url, email, password)'text'
patternThe property that contains radio valuestring regex-

Example:

{
	key: 'myMaterialInput',
	type: 'input',
	templateOptions: {
		label: "Number Input",
		placeholder:"Write a number here",
		required:true,
	        minlength: 3,
	        type:"number"
	}
}

textarea

templateOptions Configuration:

namedescriptiontypedefault
labelInput Labelstring-
placeholderInput placeholderstring-
descriptionInput descriptionstring-
requiredInput should have a valuebool-
disabledInput is disabledbool-
minlengthMinimum character length to be enterednumber-
maxlengthMaximum character length to be enterednumber-
typeInput text typestring of (text, number, url, email)'text'
patternThe property that contains radio valuestring regex-

Example:

{
	key: 'myMaterialTextarea',
	type: 'textarea',
	templateOptions: {
		label: "Textarea",
		placeholder:"Say something here",
		required:true,
		maxlength: 200
	}
}
	

select

namedescriptiontypedefault
labelRadio group Labelstring-
descriptionRadio group descriptionstring-
requiredRadio group should have a valuebool-
disabledRadio group is disabledbool-
minlengthMinimum character length to be enterednumber-
maxlengthMaximum character length to be enterednumber-
optionsArray of select options to be renderedarray[]
labelPropThe property that contains radio label if option is objectstring'name'
valuePropThe property that contains radio value if option is objectstring'value'
patternThe property that contains radio valuestring regex-

Example:

{
	key: 'myMaterialSelect',
	type: 'select',
	templateOptions: {
		label: 'Select',
		required: true,
		description : 'Select your type',
		options:[
			'string',
			2,
			{name:'label', value:'value'}
			]
	}
}

radio

namedescriptiontypedefault
labelRadio group Labelstring-
descriptionRadio group descriptionstring-
requiredRadio group should have a valuebool-
disabledRadio group is disabledbool-
minlengthMinimum character length to be enterednumber-
maxlengthMaximum character length to be enterednumber-
optionsArray of radio buttons to be renderedarray[]
labelPropThe property that contains radio label if option is objectstring'name'
valuePropThe property that contains radio value if option is objectstring'value'
patternThe property that contains radio valuestring regex-

Example:

{
	key: 'myMaterialRadio',
	type: 'radio',
	templateOptions: {
		label: 'Radio Input',
		required:true,
		description : 'Select your type',
		options:[
			"string",
			2,
			{name:'array', value:[1,2,3]},
			{name:'date', value: new Date()},
			{name:'object', value:{prop1:'value1'}}
			]
	}
}

Configuring Validation

Available validations are:

  • required
  • url
  • email
  • number
  • pattern
  • minlength
  • maxlength

Customize validation message

You can customize any of the previous validations messages by adding a message to formly's MessagesConfig.

import { Formly, FormlyConfig } from 'react-native-formly';
let {MessagesConfig } = FormlyConfig;

MessagesConfig.addType([
  {
    name: 'required',
    message: "'This field is Required!!!'"
  },
  {
    name: 'number',
    message: "viewValue+' is not a number'"
  }
]);

Overriding validations

If you ever wanted to change a validation you can override it using formly's ValidationsConfig.

import { Formly, FormlyConfig } from 'react-native-formly';
let {ValidationsConfig} = FormlyConfig;

ValidationsConfig.addType({
 minlength: {
    expression: function ({ viewValue, modelValue, param }) {
      return viewValue && viewValue.length >= param;
    },
    message:"'Minimum length is '+ param"
  }
});

Make sure that you add this validations after requiring the template

Roadmap

  • input
  • radio
  • textarea
  • checkbox
  • multicheckbox
  • customizable themes
  • select