gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

"data" option with enum value containing commas isn't working #670

Closed DookTibs closed 5 years ago

DookTibs commented 5 years ago

With a schema with a field with an enum, where a value contains a comma, Alpaca complains about an invalid value when preloading via the "data" options. This was tested with 1.5.24. Fiddle:

http://jsfiddle.net/DookTibs/hqw05jvx/25/

Two options are rendered in the form with their correct values, and submits work (not illustrated in Fiddle). But when preloading the form with data, Alpaca complains like:

This field should have one of the values in butcher,baker,candlestickmaker, programmer. Current value is: butcher,baker,candlestickmaker

I don't use Alpaca with multi-value selects but I'm wondering if I'm running into something there. Is it possible to have enum values with commas (is there a way to escape them?) or is this a bug?

BrianH85 commented 5 years ago

I'm not sure if I understand completely. But it seems like the error you get is alpaca complaining that no valid value is selected? By adding this option:

"options": { "hideInitValidationError": true }

You can prevent initial validation of the form.

clemens-tolboom commented 5 years ago

I'm facing this too. We have an schema and data value "A, B and C".

When loading it reports

alpaca-670

The HTML element contains

 This field should have one of the values in A, B and C.  Current value is: A,B and C

The subtle thing is the lack of the space after the A in Current value is: A,B and C ... it disappeared.

clemens-tolboom commented 5 years ago

Checking with the JS fiddle from issue summary my space problem is not the real problem.

Patching somewhere around alpaca.js:12757 only showed my space is really gone.

-                    "message": status ? "" : Alpaca.substituteTokens(this.getMessage("invalidValueOfEnum"), [messageValues.join(', '), this.getValue()]),
+                    "message": status ? "" : Alpaca.substituteTokens(this.getMessage("invalidValueOfEnum"), ['"' + messageValues.join('", "'), this.getValue() + '"']),

Debugging another time I found tihs.data is this.data is indeed split on the comma into two.

github-alpaca-670

(my 2 cents)

futon88 commented 5 years ago

I've encountered this bug as well. Has there been any update?

mibewh commented 5 years ago

This issue has been fixed for new builds of Alpaca: https://github.com/gitana/alpaca/commit/e5e4505cd31790ab3f19817a98bc1eda330815d2. The issue was related to how data is parsed for multiple select ListFields.