Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Form to be extended #3688

Closed
wernerkrauss opened this issue Nov 27, 2014 · 5 comments
Closed

Allow Form to be extended #3688

wernerkrauss opened this issue Nov 27, 2014 · 5 comments
Assignees

Comments

@wernerkrauss
Copy link
Contributor

Using HTML/CSS Frameworks like Bootstrap or Foundation you have to transform the Forms to be rendered properly. A current solution is to subclass Form and do changes. This is quite un-handy when you have already some Forms (e.g. MemberLoginForm) which you also have to subclass and use instead.

The Foundation solution is quite easy and just calles some stuff in forTemplate(). See https://github.com/ryanwachtl/silverstripe-foundation-forms/blob/master/code/FoundationForm.php

I think it might be quite handy if at least Form::forTemplate() would have an extension point where you can plug in some functionality for all forms globally (you'll have to check if you're in frontend manually).

@willmorgan
Copy link
Contributor

I've done SilverStripe with Bootstrap before, without ever needing to do a transformation on a Form.

You can override any template with relative ease; one thing I'd like to see by default is the form's subclass being looked for before falling back to using Form.ss.

Fields, too, can be customised in this way (using <Name>Field.ss, and <Name>Field_holder.ss).

Am I missing something? 😄

@stevie-mayhew
Copy link
Contributor

@willmorgan yes you can do that, but it would also be good if you could hook into the FormField somewhere and add classes to be all forms, perhaps through config:

FormField:
  extra_classes:
    - 'form-control'

Of course this doesn't solve the problem of the layout for a bootstrap etc. form needing to be different from the way which SS does it. We currently write every form into the template where they are used as it gives us a bit more freedom 😄

@wernerkrauss have you seen @unclecheese bootstrap module? Perhaps writing something along those lines for your own use internally would be of use?

@dhensby
Copy link
Contributor

dhensby commented Dec 17, 2014

@stevie-mayhew I agree that there needs to be a way to inject default classes into form fields

@dhensby
Copy link
Contributor

dhensby commented Jan 9, 2015

I'm currently working on something to add default_classes config to Form and FormField

@dhensby dhensby self-assigned this Jan 9, 2015
@wernerkrauss
Copy link
Contributor Author

@willmorgan the point is: i don't want to replace existing form (like login form) or forms bundled in modules with my own subclass of Form. This just doesn't feel right for me.
@stevie-mayhew yup, i know the bootstrap module. Will have to look at this a bit closer.

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

No branches or pull requests

4 participants