Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract structure from AlloyUI form builder?

I have been playing around with AlloyUI form builder but I can't find how to get the data of the form I have been editing. I looked in the doc, the code... am I blind ? :-)

Thanks! Chris

like image 745
Chris Hki Avatar asked Mar 23 '23 08:03

Chris Hki


1 Answers

Persisting the generated form to be represented later is something you must do on your own, so you can decide the structure that better suits your needs. The properties you're looking for are stored in the fields of the form.

A rough idea could be to iterate through the fields array and extract the information you want. For example:

var formXML = '<root>';

formBuilder.get('fields').each(
    function(item, index, collection) {
        var dataType = item.get('dataType'),
            indexType = item.get('indexType'),
            label = item.get('label'),
            multiple = item.get('multiple'),
            name = item.get('name'),
            options = item.get('options'),
            readOnly = item.get('readOnly'),
            repeatable = item.get('repeatable'),
            required = item.get('required'),
            showLabel = item.get('showLabel'),
            type = item.get('type'),
            width = item.get('width');

        var fieldXML = '<field>';
        fieldXML += '<type>' + dataType + '</type>';
        fieldXML += '<name>' + name + '</name>';
        fieldXML += '<required>' + required + '</required>';
        fieldXML += '</field>';
    }
}

formXML += '</root>';

Then, you can save that xml and use it later to replicate the form you edited from other parts of your site.

like image 145
jbalsas Avatar answered Apr 02 '23 04:04

jbalsas