title: How to create a submit button in react-admin which changes appearance and behaviour depending on form data and validation
body: <p>In a complex tabbed form in react-admin I need to have two submit buttons, one is the regular save button and one for altering the "status" field (advancing one workflow step) and saving the form.</p>
  
  <p>The save butten should only become active if all required fields are filled by the user.
  The other button changes its text depending on a "status" field in the record which contains the current workflow step, and is only active when the form validation for the current workflow step passes.</p>
  
  <p>So either I need a dynamic button or several buttons which show and hide depending on the "status" field.
  I think the dynamic button would be the more elegant solution.</p>
  
  <p>Below you see the code I currently have, it is more or less copied from the react-admin documentation. I need to add a custom save button as well, but it is just a subset, easy to do when the AdvanceWorkflowButton works at the end.</p>
  
  <pre><code>const AdvanceWorkflowButton= ({ handleSubmitWithRedirect, ...props }) =&gt; {
      const [create] = useCreate('posts');
      const redirectTo = useRedirect();
      const notify = useNotify();
      const { basePath, redirect } = props;
      const form = useForm();
  
      // I need to set the label dynamically ... how?
      // I also need sth like:
      // if (validationSucceeds()) enable=true
  
      const handleClick = useCallback(() =&gt; {
          // here I need to check the current content of the "status" field.... how?
          form.change('status', { "id": 2, "name": "Vorbereitung begonnen" });
          handleSubmitWithRedirect('list');
      }, [form]);
  
      return &lt;SaveButton {...props} handleSubmitWithRedirect={handleClick} /&gt;;
  };
  
  const CustomToolbar = props =&gt; (
      &lt;Toolbar {...props} &gt;
          &lt;SaveButton
              label="Speichern"
              redirect="list"
              submitOnEnter={true}
              variant="text"
          /&gt;
         &lt;AdvanceWorkflowButton /&gt;
      &lt;/Toolbar&gt;
  );
  </code></pre>