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

SelectField doesn't show value when read-only #630

Open cniesen opened 6 years ago

cniesen commented 6 years ago

The web-display / bootstrap-display view no longer displays the value with select fields. The (selected) data value isn't being displayed in read-only mode. It used to work with the 1.5.14 release.

Sample code:

$("#field1").alpaca({
    "schema": {
        "type": "string",
        "title": "Pick an Action Hero"
    },
    "view" : "web-edit",
    "options": {
        "type": "select",
        "dataSource": {
            "rambo": "John Rambo",
            "norris": "Chuck Norris",
            "arnold": "Arnold Schwarzenegger"
        }
    },
    "data": "rambo"
});

Change the web-edit to web-display.

cniesen commented 6 years ago

The issue is that in ListField.js prepareControlModel function the model.selectOptions is an empty array. The options are available under model.options.dataSource.

I guess this bug was introduced with this refactor.

cniesen commented 6 years ago

There is a timing issue with populateDisplayableText() and when the selectOptions are populated. The pull request should fix this issue.

BlueWater86 commented 6 years ago

Hi @cniesen all of the controls that extend Alpaca.Fields.ListField have many bugs since that refactor that you mentioned. The bug you resolve above happens on initial render of a form. There is another bug where if you call 'SetValue' on the root level control to update all values on a form, readonly list fields are also left blank. Very average refactor.

I will be writing a couple of tests and hopefully my pull request gets merged this time.

hpk2987 commented 4 years ago

I applied this same fix but on current master (1.5.27) it solved my problem with read only select, thanks!