Need to reset form fields of specific fields - reactjs

How to reset specific form fields in antd.
I using resetformfields(); but it resets whole form value. I want to reset particular values

In Ant design, you can use setFieldsvalue to set particular field values.
form.setFieldsValue({
fieldName: '',
});

Related

How to correctly receive an array of data in input

I have an edit form, where I have an input that I'm sending an array of data through.
However, in the edit form, even though the input is returning me an array of data to edit, they are as a single value.
That is, if I remove a data returned in this input, all are removed. Also, the names in the input are all pasted together.]
What I'd like to try if it's possible is to return the data this way in the edit form:
And from that, I could remove the name "Melissa" and submit the form again. Through autocomplete, the user should be able to search for another name to replace "Melissa", without changing the values ​​that are already present.
But I'm getting the data this way:
I created a Codesandbox of how I'm doing it in my code: https://codesandbox.io/s/intelligent-ace-9wbz44?file=/src/App.tsx
Can you help me with this?
I'm assuming you want to use testValue as the default options for your Autocomplete component.
Remove value={field.value}
Match testValue's type to studentOptions's type
const testValue = [
{
value: "João Lima",
label: "João Lima"
},
{
value: "Ana Clara",
label: "Ana Clara"
}
];
Change result to result={field.value ?? testValue}.
Working sandbox: https://codesandbox.io/s/condescending-euler-0gt9c9?file=/src/App.tsx

How do you validate a select box in React Final Form

I'm trying React Final Form. How can I validate the user has selected a value in a "select" box and that it is not longer the initial value. I'm using a Field like this, then just adding options by mapping an array.
<Field
flex="1 0 200px"
name="project-busOrgId"
component="select"
>
Your two options are field-level validation, where you specify a validate prop to <Field/> or record-level validation, where you validate all the form values at once and return an object of errors. Up to you.

Proper way to validate array inside angularjs form?

I have a form. This form contains array of products i.e
[{"productId":"12121212","count":5},{"productId":"22222222","count":6}]
What i need is to :
Validate the form on client and disable submit when any of product array fields are invalid.
Can i use validators like i work plain form fields and check like:
myForm.product[i].productId.$invalid,
myForm.product[i].productId.$error.required
?
Validate the form on server when submit and pass back errors to client. Now i attach service prop 'error', but it seems not common way to angularjs validation.
Plunker link:https://plnkr.co/edit/kbLs3SJE5ybNxIvo3ynq
Any suggestions. Thanks!
It is best to validate the input fields on client side first. To disable the submit button based on validation you can use ng-disabled="myForm.$invalid" on submit button. This will work for HTML validations on input fields like required, ng-minlength, ng-maxlength, etc.
However for complex validations on field, you can write a function and call it: ng-disabled="isFormValid()". This function will iterate through all values and check if they are valid.

Elixir ExAdmin, how to define boolean input as a checkbox?

In ExAdmin, how can I make the input field of a boolean render as a checkbox.
By default (i.e. empty register_resource App.Reservation do end) it shows up as a checkbox, but I need to customize the form and can't get it to be a checkbox when defining it in the inputs list.
register_resource App.Reservation do
form reservation do
inputs do
input reservation, :is_booked
end
end
end
The documentation mentions check_boxes and radio for groups but not for single fields.
input reservation, :is_booked will create a text field.
input reservation, :is_booked, type: :boolean will create a text field that says true as a default value.
Would like to have it as a checkbox
The problem I had was that I forgotten to define the field type in model. Once I did that it worked!
schema "users" do
...
field :active, :boolean, default: false
...
end
in admin for user.ex
inputs do
...
input user, :active
...
end

Setting DefaultValue of a directive field type

Please look at the following jsbin
You will notice that there are two fields. One is a normal input while the other is a new field type that references exampleDirective. Please note...in my real application, these fields are pulling pulled from JSON and are not manually added to the fields array.
I set the DefaultValue on each record within the fields array. Again, these default values are being pulled from JSON.
The RegularInput field is properly displaying the default within its input field.
The DirectiveInput is not. Please look at the model and you will see that the default value was applied to the field itself and not the input field (or fields if I had multiple) within the directive.
Is there a way to make DefaultValue work in this type of situation? And if not...what would the best way to get the value that I am pulling from JSON to be placed on the directive fields?
just update your incoming json to include the "defaultValue" in the form object that gets passed to your directive. Try this: http://jsbin.com/coyuriyazu/1/edit?html,js,output
I ended up fixing my issue by passing data INTO the directive.
formlyConfig.setType(
{
name: 'dirTest1',
template: '<div directive-test checked="to.IsChecked" amount="to.CoverageAmount"</div>'
});
With this approach, I can specify IsChecked and CoverageAmount in my directive and pass the values that I need when setting up the various inputs within the directive. So, when I push this field type to my fields array, I can easily set my values like so:
var newRow = {
key: TestKey,
type: dirTest1,
templateOptions: {
CoverageAmount: 12345,
IsChecked: true
}
};
vm.fields[i].fieldGroup.push(newRow);

Resources