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

Enable setting of submit-button-label in AutoForm #28

Closed
macrozone opened this issue Jun 15, 2016 · 2 comments
Closed

Enable setting of submit-button-label in AutoForm #28

macrozone opened this issue Jun 15, 2016 · 2 comments
Assignees
Labels
Type: Feature New features and feature requests

Comments

@macrozone
Copy link
Contributor

Currently you can't define the label for the submit-button in a AutoForm or QuickForm unless you implement your own QuickForm.

E.g. like this:

import {QuickForm} from 'uniforms';

import BaseForm    from './BaseForm';
import AutoField   from '../fields/AutoField';
import ErrorsField from '../fields/ErrorsField';
import SubmitField from '../fields/SubmitField';

const Quick = parent => class extends QuickForm.Quick(parent) {
    static Quick = Quick;

    getAutoField () {
        return AutoField;
    }

    getErrorsField () {
        return ErrorsField;
    }

    getSubmitField () {
        return () => <SubmitField value={this.props.submitLabel} />;
    }
};

export default Quick(BaseForm);

Now I can use <AutoForm submitLabel="Send" schema={...} />

In my code i have a slightly different SubmitField-component with a button instead of a , because supports children. So in my code i have:

getSubmitField () {
        return () => <SubmitField>{this.props.submitLabel}</SubmitField>;
    }

where submitLabel could also be a react-component.

Maybe we can add a similar property like submitLabel to the unstyled/bootstrap/semantic-implementations. (not sure if submitLabel is the right word, though).

Another solution would be to have a component that renders all fields but the submit button (similar to aldeed:autoform's afquickfiels: https://github.com/aldeed/meteor-autoform#afquickfields)

That would enable to have half-automatic forms

@radekmie
Copy link
Contributor

Separate prop for submit button label seem to be an overkill, but Auto/Errors/SubmitField configurable by props (eg. <QuickForm autoField={() => <p>Example</p>}) is quite neat option. Does it makes sense for you?


Side note: You can inherit AutoForm, not QuickForm to override getSubmitField.

@radekmie radekmie self-assigned this Jun 15, 2016
@radekmie radekmie added the Type: Feature New features and feature requests label Jun 15, 2016
@macrozone
Copy link
Contributor Author

Hi @radekmie, looks like a good option that does not need much code. I like that.

I also like the other approach with something like afquickfields. I will open a new issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features and feature requests
Projects
Archived in project
Development

No branches or pull requests

2 participants