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
607 stars 168 forks source link

Support for DatePicker #93

Closed glennswest closed 7 years ago

glennswest commented 7 years ago

Is there a way of getting json-forms to use a datepicker? Thinking also I might want to also use a picker for a table as well, for joined tables.

fabifabi commented 7 years ago

I do it using a decorator...same for color! (u look to have same need than I :) )

glennswest commented 7 years ago

Its giving me pain:

Here is the upper level:

<!DOCTYPE html>

Minidash

New

Here is the code that should add in the calendar: function mddecorate(element,schema) { name = element.tagName; switch(name){ case "INPUT": gsw = element; fieldname = element.placeholder.toLowerCase(); // element.id = BrutusinForms#0_0 if ('format' in schema){ switch(schema.format){ case "date": console.log(schema); console.log(schema.$id); console.log(element.id); var theid; // "input[id$=txtDatepicker]" theid = '#' + element.id; console.log(theid); $(theid).datepicker({dateFormat: 'yy-mm-dd'}); break; } } break; } }

Console output:Navigated to http://ctl.ncc9.com:9093/view/devices/new mddecorate.js:15 Object {type: "string", format: "date", description: "DateCreated", $id: "$.date_created"} mddecorate.js:16 $.date_created mddecorate.js:17 BrutusinForms#0_1 mddecorate.js:21 #BrutusinForms#0_1

Never see the datepicker. :(

What Im I missing

glennswest commented 7 years ago

Wow, its easy:

function mddecorate(element,schema) { name = element.tagName; switch(name){ case "INPUT": gsw = element; fieldname = element.placeholder.toLowerCase(); // element.id = BrutusinForms#0_0 if ('format' in schema){ switch(schema.format){ case "date": $(element).datepicker(); break; } } break; } }

glennswest commented 7 years ago

For more readable version: https://github.com/glennswest/microdash/blob/065e6983a0f8b77a90d5061959c9a216ac343bce/public/mddecorate.js

Thanks for the help. Figured it out by reading brutusin/json-forms code, reading others code is the best way to learn.

idelvall commented 7 years ago

I'm late here, glad to see you figured it out