brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
606 stars 168 forks source link

Support for type 'password' #115

Open pmerienne opened 6 years ago

pmerienne commented 6 years ago

I think it could be really good to add support of a 'password.

I'm not a good JS developper so I'm having troubles to create a nice PR for this feature. Thus I can't provide any help with this issue.

hxh-robb commented 6 years ago

Seems like it isn't a native support. You can have a look at issue #97 , but we can use "decorator" to meet this requirement.

Please check out this example. https://jsfiddle.net/hxh_robb/xk663z01/4/

// add support for password and file fields
BrutusinForms.addDecorator(function(element, schema) {
  if (element.tagName) {
    var tagName = element.tagName.toLowerCase();
    if (tagName === "input" && schema.type === "string") {
        if( schema.format === 'inputstream' || schema.format === 'file' ){
        element.type = 'file';
      } else if ( schema.format === 'password' ){
        element.type = 'password';
      }
    }
  }
});

Hope this help.