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

Set view for a field has no effect #693

Open mosling opened 5 years ago

mosling commented 5 years ago

Starting with the example in the URL file documentation and set "view":"bootstrap-display has the effect that was wished (i.e. has a clickable link).

But do the same for a field hasn't the same effect. Here is the code which can be copied into Example 1 of the URL documentation and no link is generated.

$("#field1").alpaca({
    "data": {
        "url": "http://www.alpacajs.org"
    },
    "options": {
        "fields": {
            "url": {
                "type": "url",
                "view": "bootstrap-display"
            }
        }
    },
    "schema": {
        "properties": {
            "url": {
                "type": "string",
                "format": "uri",
                "title": "Alpaca Url"
            }
        }
    }
});

Adding a "view":"bootstrap-display" has the desired effect but for all fields.

beccon4 commented 5 years ago

I found the following solution of using a template for a custom field and feed in the field's data via the {{data}} placeholder. This works for inserting custom widgets such as buttons etc. as well.


{
    "data":{
        "linkmich":"WinkeWinke",
        "name":"OhOh"
    },  
    "schema": {
        "title":"Testseite",
        "description":"Test mit AJAX",
        "type":"object",
        "properties":{
            "name":{
                "title":"Name",
                "type":"string"
            },  
            "linkmich":{
                "title":"WinkeWinke",
                "type":"string"
            },  
        }   
    },  
    "view":{
        "fields":{
            "/linkmich":{
                "templates":{
                    "control-text":"<a href='http://teletubbies.com/'>{{data}}</a>"
                }   
            }   
        }   
    }   
}
mosling commented 5 years ago

Thanks for this nice workaround.

dzg commented 5 years ago

@beccon4 Thanks! This was driving me nuts!

dzg commented 5 years ago

Does anyone know how I can set a single field to use the "bootstrap-dispay" view? Been trying for hours.

jellomold commented 5 years ago

I thought i was losing my mind. that something changed in one of the dependencies. 1.5.22 didn't have this problem. 1.5.27 does. whew! (yes, i'm slow to upgrade) I use view overrides in the options a LOT.

jellomold commented 4 years ago

I've downloaded the whole codebase. hunted around aimlessly in the commits for any file that mentions "view". I don't know when the issue was introduced, but it affects me everyday and i'd love to learn how to fix it. even if cloudcms isnt' going to address it, how can i? is there anyone that knows this codebase and wants to help me get up to speed so i can possibly contribute?

PeterMead commented 3 years ago

It was changed in f8e70e4467ce15ece01cd42e4aaf7d05659f5169.

I too used this feature and need it to work again.

mrobock commented 2 months ago

Thanks for the link @PeterMead, simply reverting this change seems to work for us (we actually have a local copy of the compiled JS so are able to make these change without needing to deal with forking or PRs).

To me that commit seems to be the opposite behavior that one would want. It prioritizes form/parent view choices over ones assigned specifically to the element. I'd think you'd want the element view choice to have priority.