cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PRV2TECH
Regular Visitor

How to Make Field Optional in Portal Web Form Step

I have Portal Web form with multiple steps. On one of the step i am using Form created in Entity(CDS). Entity field is Business Recommended which then can be marked as Required on the web form. Field is used in Multiple Web Forms and on one of the web Form i want to make it optional. I can remove Business recommendation for the field and write Javacript to make it Mandatory but because the field is used in many forms and just one form need that to be made Optional so thinking of implementing something that wont break existing setup. Can someone please suggest how this can be achieved. Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Great news. Could you mark this as 'Solved' if all is now working as you expected.

View solution in original post

8 REPLIES 8
hardikv
Solution Sage
Solution Sage

Hi @PRV2TECH

You can set field as Optional from entity meta data.

 

Please refer below link:

https://www.google.com/amp/s/www.inogic.com/blog/2018/12/how-to-make-optional-fields-as-mandatory-fi...

 

--------------------------
If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

Fubar
Solution Sage
Solution Sage

Note: you cannot make a mandatory field optional via metadata as suggested by someonelse

 

In your case, on the form that it needs to be optional, on the Entity Form uncheck the option that makes Business Recommended Mandatory, if you have other Business Recommended fields on that form create Metadata items for that Entity Form to set each of those attributes mandatory.

Hi

 

I actually don't think you can bypass that via JS or anything else in the Portals. It will enforce your entity model restrictions.

The only way here is doing the opposite, keeping Optional in the CDS level, and making mandatory via Web Form Metadata for your other pages.


------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

PRV2TECH
Regular Visitor

Thank you everyone, i have to implement this using Javascript which worked fine. 

 

ValidatorEnable($('[id*=RequiredFieldValidator"+fielName+"]')[0], false);
$('#"+fielName+"_label').parent().removeClass('required');

 

Below post helped the implementation. Tried to get around using webtemplate but couldn't get working using Liquid in Webform.

https://www.futurezconsulting.com/2018/06/04/portals-validators/

 

Hi @PRV2TECH,

Have you tested that it works? I've had issues with removing the validators client-side where the form would still not submit due to server-side failure. Typically, removing validators with JS works when it was originally added with JS. I can't recall if my issues were with Required via field vs. Entity Form Metadata, or both.

Yes, you can remove a required field using JS.

I've done this before on a jQuery document ready. Something like this will do it.

 

//eg. removeValidator("customerid")
function removeValidator(fieldName) {
  var count = 0;
  for(var i =0; i < Page_Validators.length - count; i++){
    if (Page_Validators[i - count].id == "RequiredFieldValidator" + fieldName) {
      Page_Validators.splice(i - count, 1);
      count++;
    }
  }
  $("#" + fieldName + "_label").parent().removeClass("required");
}

 

 

 

I have used below function in live portal website and working as expected. Change field name and use below script inside Custom Javascript of Web Form -> Web Step. 

 

if (window.jQuery) { (function ($) { $(document).ready(function () { if (typeof (Page_Validators) === 'undefined') return; var fieldName="customer_name"; ValidatorEnable($('[id*=RequiredFieldValidator"+fieldName+"]')[0], false); $('#"+fieldName+"_label').parent().removeClass('required'); }); }(window.jQuery)); }

Great news. Could you mark this as 'Solved' if all is now working as you expected.

Helpful resources

Announcements
Welcome Super Users.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,240)