danhunsaker / angular-dynamic-forms

Build Forms in AngularJS From Nothing But JSON (please see Alternatives in the README)
MIT License
379 stars 140 forks source link

Add support for user-defined classes #34

Closed jannickfahlbusch closed 9 years ago

jannickfahlbusch commented 9 years ago

I've added a rudimentary support to add classes to each element.

To add a specific class to an element, you should write down the wanted classes in the "class"-variable in each element-section.

The support to define classes via the Shema-JSON will follow.

danhunsaker commented 9 years ago

Wait, what's the point of this one? How is this any different from using attributes.class in the template?

Also confused why you added a support key to every type, then checked for it even within blocks where the type is known. Don't see the advantage of that approach in any case.

jannickfahlbusch commented 9 years ago

I didn't find any method to add classes to specific elements. Maybe i didn't saw it or it wasn't there.

I' m not a Javascript Expert, so i added this line, where it works and adds the class for me. (It should be just a rudimentary support for this functionality as i said)

danhunsaker commented 9 years ago

The changes here require editing the script itself to set up the desired classes on each element, and even once that's done, each such element will have the same class, regardless of where it falls in the output. This is not likely to be your desired effect. Instead, your template should use the attributes.class option to set the desired class(es) on a field-by-field basis. Something like this:

... {
        "type": "text",
        "model": "username",
        "label": "Username",
        "attributes": {
            "class": "username text-input login",
            "required": "required"
        },
    } ...

should do the trick.