File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ A [live playground](https://mozilla-services.github.io/react-jsonschema-form/) i
4949 - [ Textarea rows option] ( #textarea-rows-option )
5050 - [ Placeholders] ( #placeholders )
5151 - [ Field labels] ( #field-labels )
52+ - [ HTML5 Input Types] ( #html5-input-types )
5253 - [ Form attributes] ( #form-attributes )
5354 - [ Advanced customization] ( #advanced-customization )
5455 - [ Field template] ( #field-template )
@@ -700,6 +701,19 @@ const uiSchema = {
700701};
701702```
702703
704+ ### HTML5 Input Types
705+
706+ If all you need to do is change the input type (for using things like input type="tel") you can specify the ` inputType ` from ` ui:options ` uiSchema directive.
707+
708+ ``` jsx
709+ const schema = {type: " string" };
710+ const uiSchema = {
711+ " ui:options" : {
712+ inputType: ' tel'
713+ }
714+ };
715+ ```
716+
703717### Form attributes
704718
705719Form component supports the following html attributes:
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ module.exports = {
2626 title : "Password" ,
2727 minLength : 3 ,
2828 } ,
29+ telephone : {
30+ type : "string" ,
31+ title : "Telephone" ,
32+ minLength : 10 ,
33+ } ,
2934 } ,
3035 } ,
3136 uiSchema : {
@@ -46,6 +51,11 @@ module.exports = {
4651 date : {
4752 "ui:widget" : "alt-datetime" ,
4853 } ,
54+ telephone : {
55+ "ui:options" : {
56+ inputType : "tel" ,
57+ } ,
58+ } ,
4959 } ,
5060 formData : {
5161 firstName : "Chuck" ,
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ function BaseInput(props) {
1616 registry,
1717 ...inputProps
1818 } = props ;
19+
20+ inputProps . type = options . inputType || inputProps . type || "text" ;
1921 const _onChange = ( { target : { value } } ) => {
2022 return props . onChange ( value === "" ? options . emptyValue : value ) ;
2123 } ;
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ describe("uiSchema", () => {
8989 funcNone : { type : "string" } ,
9090 stringAll : { type : "string" } ,
9191 stringNone : { type : "string" } ,
92+ stringTel : { type : "string" } ,
9293 } ,
9394 } ;
9495
@@ -126,6 +127,11 @@ describe("uiSchema", () => {
126127 stringNone : {
127128 "ui:widget" : "widget" ,
128129 } ,
130+ stringTel : {
131+ "ui:options" : {
132+ inputType : "tel" ,
133+ } ,
134+ } ,
129135 } ;
130136 } ) ;
131137
@@ -195,6 +201,12 @@ describe("uiSchema", () => {
195201 expect ( widget . style . margin ) . to . equal ( "" ) ;
196202 expect ( widget . style . padding ) . to . equal ( "" ) ;
197203 } ) ;
204+
205+ it ( "should ui:option inputType for html5 input types" , ( ) => {
206+ const { node } = createFormComponent ( { schema, uiSchema, widgets } ) ;
207+ const widget = node . querySelector ( "input[type='tel']" ) ;
208+ expect ( widget ) . to . not . be . null ;
209+ } ) ;
198210 } ) ;
199211
200212 describe ( "nested widget" , ( ) => {
You can’t perform that action at this time.
0 commit comments