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

[Question] set submit-button-label in AutoForm #155

Closed
cyclops24 opened this issue Dec 27, 2016 · 6 comments
Closed

[Question] set submit-button-label in AutoForm #155

cyclops24 opened this issue Dec 27, 2016 · 6 comments
Assignees
Labels
Type: Question Questions and other discussions

Comments

@cyclops24
Copy link

cyclops24 commented Dec 27, 2016

Hi @radekmie,
I want to customize submit button in an Autoform. Now it's show "Submit Query" for button label.
I also see this and this but can't set submit-button label.
It's my try:

import {SubmitField} from 'uniforms-bootstrap3';
const customSubmitField = () =>
        <SubmitField>Login</SubmitField>;
<AutoForm schema={LoginSchema} placeholder={true}
                          getSubmitField={customSubmitField}
                          onSubmit={doc => console.log(doc)}>

Can you help me to do this?

@radekmie
Copy link
Contributor

If you still want to use fully automatic AutoForm, i.e. <AutoForm schema={...} onSubmit={...} />, then pass an additional submitField prop with your custom SubmitField.

Example:

import SubmitField from 'uniforms-unstyled/SubmitField'; // <- !

const MySubmitField = props =>
    <SubmitField value="Submit Label Here" /> // It's <input type="submit" />
;

// Later...

<AutoForm schema={...} onSubmit={...} submitField={MySubmitField} />

If you are using not-so-fully-automatic AutoForm:

<AutoForm schema={...} onSubmit={...}>
    <AutoField ... />
    {/* ... */}

    {/* Like this */}
    <MySubmitField />

    {/* Or directly */}
    <SubmitField value="Submit Label Here" />
</AutoForm>

@radekmie radekmie self-assigned this Dec 27, 2016
@radekmie radekmie added the Type: Question Questions and other discussions label Dec 27, 2016
@radekmie
Copy link
Contributor

I'll close it. If you have more questions, just let me know.

@cyclops24
Copy link
Author

@radekmie Thanks man. I test it and works well.

@bennycode
Copy link
Contributor

I tried it like this:

import JSONSchemaBridge from 'uniforms-bridge-json-schema';
import {AutoFields, AutoForm, ErrorsField, LongTextField, SubmitField} from 'uniforms-material';
// ...

const strategyAddSchema = {
  title: 'Strategy',
  type: 'object',
  properties: {
    // ...
  },
  required: ['config', 'label', 'name', 'user', 'version'],
};

const strategyAddBridge = new JSONSchemaBridge(strategyAddSchema, () => null);

const strategyAddForm = (
  <AutoForm
    schema={strategyAddBridge}
    onSubmit={async (model: StrategyEntityProps) => {
      // ...
    }}>
    <AutoFields />
    <ErrorsField />
    <SubmitField value={'Test'} />
  </AutoForm>

But the submit button still shows text "Submit" instead of "Test".

image

@radekmie, have I missed something? 🤔

@radekmie
Copy link
Contributor

radekmie commented Mar 8, 2021

Hi @bennycode. It depends on your theme - in uniforms-material it looks like this, hence you should use label or children props instead of value.

@bennycode
Copy link
Contributor

<SubmitField label="Test" /> did the trick! Thank you!!

@radekmie radekmie moved this to Closed in Open Source Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Questions and other discussions
Projects
Archived in project
Development

No branches or pull requests

3 participants