Form validation and submission can be managed/overridden from JavaScript. To do this:

Example:

import { RPCFormBase, registerHandler } from '@mod-publisher/js/forms';

class RTDForm extends RPCFormBase
{
  constructor(node)
  {
    super(node);
  }
  onSubmitSuccess(result)
  {
    qS('#rtdformresponse').textContent = JSON.stringify(result);
  }
}

registerHandler("mymodule:rtdform", node => new RTDForm(node));

The FormHandler/RPCFormBase offer the following api:

- getFieldValue(field) - override this to implement your own field handling

- getFormExtraSubmitData() - override this to pass on aditional values to your form as 'formextradata'

- onSubmit() - override this with your own submit handling (this function gets invoked when the submit event handler would fire). if you override this, be sure to invoke submit()

- onSubmitSuccess() - override this with your on-submit-success handling. An alternative to submit().then(myonsuccess). Receives the data that the promise would have resolved with

- onSubmitFailed(errors, result) - any errors triggered by `work->AddError` will be added as the first parameter of the function

Modality layer during submission

Override onRPC, eg:

async onRPC(promise)
{
  let overlay = domtools.create('div',{className: "rpc__overlay"});
  document.body.appendChild(overlay);
  await promise;
  document.body.removeChild(overlay);
}
PreviousNext

Comments