Permalink
Browse files

add option to allow hidding inputs that require no selection from user

for example a select with one option
  • Loading branch information...
1 parent 1938de4 commit 7e406310d174966293afa78f3a28327f7286dfae @marianoguerra committed Aug 22, 2012
Showing with 42 additions and 3 deletions.
  1. +16 −0 js/demos.js
  2. +26 −3 src/json.edit.js
View
@@ -691,6 +691,22 @@
}
],
[
+ "Field required with only one enumerated value and option hideIfNoSelection",
+ "this widget will be hidde since there is nothing to select",
+ {
+ "order": ["color"],
+ "required": ["color"],
+ "properties": {
+ "color": {
+ "je:options": "hideIfNoSelection",
+ "type": "string",
+ "title": "Color",
+ "enum": ["green"]
+ }
+ }
+ }
+ ],
+ [
"Array",
"",
{
View
@@ -838,22 +838,45 @@
return ns.classesList(classes).join(sep || " ");
};
+ priv.hasOption = function (opts, optionName) {
+ var options = opts["je:options"];
+
+ if ($.isArray(options)) {
+ return $.inArray(optionName, options) !== -1;
+ } else if (typeof options === "string") {
+ return options === optionName;
+ } else {
+ return false;
+ }
+ };
+
priv.genField = function (fid, opts, required, util) {
var
id = ns.id(fid, true),
inputId = ns.id(fid + "-input", true),
- type = opts.type || getType(opts);
+ type = opts.type || getType(opts),
+ input = priv.input(fid, type, inputId, opts, required, util),
+ result;
- return {
+ result = {
"div": {
"id": id,
"class": priv.genFieldClasses(fid, opts, " ", required),
"$childs": [
priv.label(opts.title, inputId),
- priv.input(fid, type, inputId, opts, required, util)
+ input
]
}
};
+
+ if (priv.hasOption(opts, "hideIfNoSelection") &&
+ input.select &&
+ input.select.$childs.length === 1) {
+
+ result.div.style = "display: none";
+ }
+
+ return result;
};
priv.validateJson = function (name, value, schema, required) {

0 comments on commit 7e40631

Please sign in to comment.