how to make a custom field mandatory (from widget) in a record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 11:55 PM
Hi Team,
We have a record producer, where a custom field(var_dl_role) is being used from a widget(dl_role). This widget contains 3 fields in total. Need to make this custom field(var_dl_role) as mandatory, so in the widget, have used "required" in HTML. However it is not working as user is able to submit without filling it though we can see an astric *(mandatory) sign before field.
Later added an on submit client script to validate the custom field value, but the value is always coming as empty only, so client script in not validating properly(i am thinking, since widget having 3 fields, so not able to capture the value...).
Could anyone please suggest how to achieve that.
Thanks
Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 12:21 AM
Hi @skumar_srbh,
Create the 3 variables in the catalog item (as hidden fields), write the values from the widget to these variables, so you can use an onSubmit client script.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 12:37 AM
Can you share the screenshot and script used
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 07:11 AM
Solution: To make the custom field `var_dl_role` mandatory and validate its value in the client-side script, you can use the `required` attribute in the field and also add a `default` attribute to set a default value for the field. Additionally, you can use the `pattern` attribute to specify a regular expression that the value must match.
Here's an example of how you can modify the field:
```
Role:
Select a role Admin
*
```
In the above code, we have added the `required` attribute to the `select` element, which will make the field mandatory. We have also added the `pattern` attribute to specify that the value must match a regular expression `[a-zA-Z0-9_]+`, which will ensure that only alphanumeric characters and underscores are allowed.
We have also added a default value of `""` to the `select` element, which will be displayed as the selected value if no other value is provided.
Reference 1: W3Schools - HTML Required Attribute
* The W3Schools article provides a detailed explanation of the `required` attribute in HTML, including examples and usage.
Reference 2: MDN Web Docs - HTML pattern Attribute
* The MDN Web Docs article provides a detailed explanation of the `pattern` attribute in HTML, including examples and usage.
Reference 3: Bootstrap - Forms and Validation
* The Bootstrap documentation provides a detailed explanation of how to use forms and validation in Bootstrap, including examples and usage.
Additional Information:
* To validate the value of the custom field in the client-side script, you can use the `value` property of the `select` element, like this: `if ($('#var_dl_role').val() === '') { // do something }`.
* You can also use the `change` event of the `select` element to validate the value when it changes, like this: `$('#var_dl_role').change(function() { // do something })`
* If you want to validate the value of the custom field only when the form is submitted, you can use the `submit` event of the form, like this: `$('#myForm').submit(function() { // do something })`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:58 AM
Hello. You can use a variable of type custom or custom with label in the record producer, choose your widget and then change the variable type to single line text. The widget field of the type specifications will still be filled in the background and although the variable is now a single line text it will render as the widget, however now you have the option to select mandatory in the variable's form. If this doesn´t work you can enforce $scope.error logic in the client controller of the widget and use a default value to trigger the invalid submission input.
Hope this helps 🙂