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

Select with optionLabels does not raise change event #612

Open WhileTrueEndWhile opened 6 years ago

WhileTrueEndWhile commented 6 years ago

Issues since version 1.5.24 compared to version 1.5.23

Hi,

please try the following configuration (on e.g. http://www.alpacajs.org/docs/fields/select.html):

{
    "data": "coffee",
    "schema": {
        "enum": ["a", "b", "c"]
    },
    "options": {
        "optionLabels": ["vanilla", "chocolate", "coffee"],
        "events": {
            "change": function() {alert(this.getValue())}
        }
    }
}

Try this with and without the optionLabels. If you add the optionLabels it does not work anymore.

The output is then broken, too! The field's value remains undefined.

Thank you!

WhileTrueEndWhile commented 6 years ago

Update:

I can't reproduce it by myself today, sorry! But there are breaking changes at least. Since version 1.5.24 the multiselect returns an object like

{
    value: 1    // data
    text: "One" // optionLabels[i] 
}

instead of simply 1

So alpaca produces a JSON object that is not valid. A schema validation would fail because in this case the type is a primitive and alpaca returns an object.

{
    "data": "coffee",
    "schema": {
        "type": "array",
        "items": {
            "enum": ["a", "b", "c"]   
        }
    },
    "options": {
        "type": "select",
        "events": {
            "change": function() {alert(JSON.stringify(this.getValue(), null, "  "))}
        }
    }
}

Thanks!

WhileTrueEndWhile commented 6 years ago

Update 2:

This configuration shows my problem in the first case:

{
    "data": null,
    "schema": {
        "type": "integer",
        "enum": [
          1,
          2
        ]
    },
    "options": {
        "type": "select",
        "events": {
            "change": function() {alert(this.getValue())}
        }
    }
}

The value is always null! Seems that alpaca does not accept integer types. Number works.

seanvree commented 6 years ago

Yup, just discovered this with the new verison as well.

image

WhileTrueEndWhile commented 6 years ago

Thank you for replying to this confusing thread. So, please let me know, If you have some "migration trouble", too. I had to change some templates, but this is not enough.

I would assume that this worked with the old version:

{
    "data": false,
    "schema": {
        "type": "boolean",
        "enum": [false, true]
    },
    "options": {
        "optionLabels": ["Not True", "Not False"],
        "view": {
            "parent": "bootstrap-display-horizontal"
        }
    }
}

Now it shows the raw data (without escaping as normal) and does NOT display the optionLabels... In my app the optionLabels are some font awesome chars (\uXXXX) which do not appear if the new version is in use. It shows "false" or "true".

quakedc commented 6 years ago

I'm not sure if this is the same issue or a related issue but I'm going to post it here. It looks like the change event is being fired twice in v1.5.24 vs once in v1.5.23 (which is the proper behavior). Refer to this fiddle:

https://jsfiddle.net/9yr9dLaz/

Can we get this fixed immediately? This is preventing me from updating to the latest version.

alemangui commented 5 years ago

@quakedc I'm getting the same problem. I am going to raise another issue to increase visibility of this to the Alpaca team.