diff --git a/src/js/Alpaca.js b/src/js/Alpaca.js index 156d561a0..a3281f473 100644 --- a/src/js/Alpaca.js +++ b/src/js/Alpaca.js @@ -943,31 +943,36 @@ */ guessOptionsType: function(schema) { - var type = null; + // check if it has format defined + if (schema.format && Alpaca.defaultFormatFieldMapping[schema.format]) + { + return Alpaca.defaultFormatFieldMapping[schema.format]; + } if (schema && typeof(schema["enum"]) !== "undefined") { if (schema["enum"].length > 3) { - type = "select"; + return "select"; } else { - type = "radio"; + return "radio"; } } - else - { - type = Alpaca.defaultSchemaFieldMapping[schema.type]; - } - // check if it has format defined - if (schema.format && Alpaca.defaultFormatFieldMapping[schema.format]) - { - type = Alpaca.defaultFormatFieldMapping[schema.format]; + // type: ["string", "null"] is a valid way of defining an optional + // field that can be either a string, or null. Use the first non-null type. + var schemaType = schema.type + if (Alpaca.isArray(schemaType)) { + for (var i = 0; i < schemaType.length; i++) { + if (schemaType[i] === 'null') continue; + schemaType = schemaType[i]; + break; + } } - return type; + return Alpaca.defaultSchemaFieldMapping[schemaType]; }, /**