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

Creating an arbitrary button within a form? #613

Closed roypardi closed 6 years ago

roypardi commented 6 years ago

(this isn't really an "issue" but I've exhausted all other resources)

I need to be able to add buttons within a form ( for Electron desktop app: buttons to select files, pick directories, etc.). I've dug through all the documentation and searched through all the past issues, where I've seen similar needs posted but no real solutions.

I've tried adding a <button> to a template and ended up with the result in the image below. That is not really a workable solution. I've seen some references in the "issues" about a "button" field type but I have not been able to get that to work.

I've posted project code and details over on stackoverflow but Alpacajs doesn't seem a very active topic there. Does anyone have any suggestions or can give me a gentle shove in the ("a") right direction? I'm no Javascript/HTML hero but I can usually sort things out but this has me stumped.


screen shot 2018-03-07 at 8 39 08 pm
WhileTrueEndWhile commented 6 years ago

You can find the template for a form element here: https://github.com/gitana/alpaca/blob/master/src/templates/web-edit/control.html In your case, the property path is: /path/projectPath Copy the template from above and paste it into your options as follows:

{
    ...
    "options": {
        "view": {
            "fields": {
                "/path/project/path": {
                    "templates": {
                        "control": `INSERT TEMPLATE HERE`
                    }
                }
            }
        }
    }
    ...
}

Please note the quotation marks. Now you can insert the button into the template, but you are on your own when it comes to event handling...

roypardi commented 6 years ago

Thanks! That helped a lot