简体   繁体   中英

Fill alpaca properties with a variable

I need to assemble a form dynamically using Alpaca Forms. I have the code below:

$("#form").alpaca({        
    "schema": {            
        "type":"object",
        "properties": {                
            "email": {
                "type":"string",
                "title":"E-mail",
                "required":true
            },
            "mensagem": {
                "type":"string",
                "title":"Mensagem",
                "required":true
            }                                        
        }
    }
});

And it needs to be filled in using variables for it to be generic, because the amount of fields that the form will have will always vary. Ex: sometimes in addition to the "email", "mensagem" properties, I will have the "assunto", "remetente", "destinatario" properties

it would need to look something like this:

$("#form").alpaca({
    "schema" : { schemaVariable }        
});

What you want to achieve is possible, you just need to remove the braces from your variable and use proper JSON object declaration.

"schema" : schemaVariable

here's a working fiddle for this. Tell me if you need something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM