Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

Horizontal form #8

Closed
dmatesic opened this issue Mar 13, 2015 · 12 comments
Closed

Horizontal form #8

dmatesic opened this issue Mar 13, 2015 · 12 comments

Comments

@dmatesic
Copy link

How would I make the form horizontal? http://getbootstrap.com/css/#forms-horizontal

@kentcdodds
Copy link
Member

Like this :-)

@kentcdodds
Copy link
Member

Let me know if you need any more help :-)

@markleusink
Copy link

@kentcdodds
Copy link
Member

👍 thanks! Updating the original link as well.

@robrothedev
Copy link

Just started using Angular Formly about 3 hours ago and needed a horizontal form. Talk about perfect timing :) Got it working like a charm and added a horizontalSelect type to boot. Thanks again!

@robrothedev
Copy link

One thing I did notice, however, is that the templateOptions: {required: true} no longer provides the asterisk next to the label. I can manually add it to '{{to.label}} *' for a workaround in the setWrapper template.

@kentcdodds
Copy link
Member

@robrothedev
Copy link

Works great. Thanks!

@tarkanlar
Copy link

how can i make horizontalSelect ?

@robrothedev
Copy link

Per the documentation added here: http://angular-formly.com/#/example/bootstrap-specific/bootstrap-horizontal you can add a formlyConfigProvider.setType({}) for a select.

angular
    .module('app',['formly','formlyBootstrap'])
    .config(config);

function config(formlyConfigProvider) {
    // custom configuration for the formly templates
    formlyConfigProvider.setWrapper({
        name: 'horizontalBootstrapLabel',
        template: [
            '<label for="{{::id}}" class="col-sm-2 control-label">',
            '{{to.label}}  {{to.required ? "*" : ""}}',
            '</label>',
            '<div class="col-sm-9">',
            '<formly-transclude></formly-transclude>',
            '</div>'
        ].join(' ')
    });

    // horizontal inputs
    formlyConfigProvider.setType({
        name: 'horizontalInput',
        extends: 'input',
        wrapper: ['horizontalBootstrapLabel', 'bootstrapHasError']
    });

    // horizontal selects
    formlyConfigProvider.setType({
        name: 'horizontalSelect',
        extends: 'select',
        wrapper: ['horizontalBootstrapLabel', 'bootstrapHasError']
    });
}

HTML

<form class="form-horizontal">
  <formly-form
     model="ctrl.form_model"
     fields="ctrl.form_fields">
  </formly-form>
</form>

@tarkanlar
Copy link

Thanks @robrothedev, i should have seen that , sorry

@robrothedev
Copy link

Not a problem and you're welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants