Hide form on submission

Is it possible to use RunJS to hide a form block after it’s successfully submitted?

I’ve got a form on a page and when submitted I want it to be hidden and another form to become unhidden. I can’t seem to find a way to do this with RunJS but am I missing something?

To work around the issue I’m currently setting up the Linkage rules and triggering a full refresh of the page.

Thanks in advance for any help.

Try

  • ctx.getModel(‘UID’).setHidden(true) to hidden a form block
  • ctx.getModel(‘UID’).setHidden(false) to show a form block

Following pictures show the configuration for hidden top form and show bottom form when top form submitted:

1 Like

Thank you so much, I’m very close now I think. I just can’t quite get the form to submit as well as hiding.

If I use an event flow on a normal Submit button then it submits but the flow never runs.

If I use a JS action button it will hide and show correctly but it will not submit the form. It’s an add form and the entry in the database is never saved, there is no error in the browser console. The code I’m using is below if you’re able to point out where I’m going wrong:

// Validate form
try {
  await ctx.form.validateFields()
} catch (e) {
  ctx.message.error("Registration form not valid");
  ctx.exit();
}

// Submit form
ctx.form.submit();
ctx.message.success("Registration saved");
  
// Hide step 1 form
ctx.getModel('60d12f50a9d', true).setHidden(true);
// Show step 2 form
ctx.getModel('b9871931a7e', true).setHidden(false);

P.S. A note for anyone finding this in the future, I needed to add the extra “true” parameter to getModel for it to be able to find the forms.

Above code actually works in latest alpha NocoBase on my side: the form data was saved in database.

1 Like

Thank you, I updated to the latest stable and it’s now working. I’m not sure if some cache was cleared or it was fixed in the update but it’s now working. Really appreciate the help :slight_smile: