bietkul/react-reactive-form

isRequired flag in FormGenerator controls to show asterisk (*) in label

arahmanali opened this issue · 4 comments

Hi i am using FormGenerator API for my form i want to show the asterisk (*) on label if the control is required but could not find a flag in render args, could anyone please guide?

You can access the control in your render component, A control has these properties which can be used to render your UI.

I'm not sure but what I understand that you want to show an asterik on label if a required validator is set to the control. You can check this by finding out the required validator in the validators list of a control.

@bietkul yeah i found out there was a function validator() in control args but when i call without any param it throws an error evaluating control.value but when i pass empty string it returns an object { required: true }

could you please clarify what argument it expects ?

Control config has a meta key which accepts an object (Whatever you define here can be accessed in component by using control.meta), I think you can use it to pass a flag to tell if the component is required or not.
For e.g

first_name: {
      render: TextInput,
      meta: {
        label: "First Name", // Or solve it by passing a label with asterik like `First Name *`
        placeholder: "Enter first name",
        required: true
     },
     options: {
        validators: Validators.required
     }
}

great thanks