when to use array as validateTrigger in antd form? - reactjs

in antd Form component there is validateTrigger property that can get a string or array of strings as value.when and why we should use array of strings?
antd form api

In validateTrigger property you can add string like
validateTrigger="onBlur"
or array of string with various input events like
validateTrigger={["onBlur", "onFocus", "onInput"]}
Example: https://codesandbox.io/s/registration-antd-4-24-2-forked-jon6u7
If you want to add multiple input events then you can add it with string array in validateTrigger.

when you want to validate the fields at the same time their values change
you don't need to submit first to see if your fields been have filled with the right values or not.
you can use this link for more information

Related

React Material-Table - How can I add commas between cell that is rendered from fetched array?

I'm using Material Table for managing workstations. Some of the data I receive are arrays, they are automatically iterated and displayed in cell but without commas.
Current behavior picture
What I'm trying to achieve
I feel like overriding whole cell component is overkill and I would like to avoid modyfing fetched array. Is there is any way that I can modify that iteration done by Material Table at "MTableCell" component ? Or maybe there is some smarter way of doing this ?
Assuming attribs is your data as array (as shown in the picture):
const attribs = ['ATTRIBUTE1', 'ATTRIBUTE2', 'ATTRIBUTE3'];
You can use reduce to convert that to a comma-separated string:
const separated = attribs.reduce((prev, current) => `${prev},${current}`);
And then feed that into the material table cell. You can check a simple example here: https://codesandbox.io/s/basictable-material-demo-forked-19c9z?file=/demo.js

Split string in React

I am trying to split a string being received from a props.
For example:
this.props.searchedBook=Cinderella (a fairy tale).
I am displaying that data like:
<span>You currently don't have data for <p>{this.props.searchedBook}</p></span>
I want to display only Cindrella. How do I do that?
If the name is always coming first in this.props.searchedBook, then you can use this
this.props.searchedBook.split(' ')[0]

Codename One - get selected text from AutoComplete

How can I get the complete selected text from an AutoComplete TextField?
If I use getText(), I only get the few letters the user has input so far.
Example: I write "flo" and then select "Flowers" from the list, but getText() gives me "flo"
AutoCompleteTextField auto = new AutoCompleteTextField(arrayWithNames);
auto.setMinimumLength(4);
auto.addListListener((ActionEvent evt1) -> {
String lookedFor = auto.getText();
Hashtable<String,Object> match[] = findMatch(lookedFor);
if(hMatch.length>0){
contElements.removeAll();
for (Hashtable<String, Object> Match1 : match) {
...
...//fill the Container with the names found
...
}
}
});
How it works
I am using the AutoComplete TF as a search button.
I have an array with all the names in my list.
Then I populate the Auto with the array.
The user selects a name from the Auto and then I search the value that is being "lookedFor" using the findMatch(). It returns a new array with the found entries.
I need the complete name from the list so I can use the findMatch() method, but when I use getText() from the Auto, it only returns the letters the user entered, and not the whole name, so my method does not work, since I am comparing whole Strings.
(I am using the Auto because it is very convenient if people remember only a part of the name they are looking for)
If you subclass AutoCompleteTextField you can access the selected text internally via getSuggestionModel().getItemAt(getSuggestionModel().getSelectedIndex()). Now you can define a public getter method getSelectedText() or something on your derived class.
I am not sure you are using the AutoCompleteTextBox correctly.
The entire purpose of the AutoCompleteText box is to help you assist the user in selecting from a list of valid requests,
You should not be getting the value of getText() until the user is ready to submit the form where the AutoCompleteTB is located.
This WILL help if you haven't already looked here:
https://www.codenameone.com/javadoc/com/codename1/ui/AutoCompleteTextField.html#getPropertyTypes--
Good luck!

How to insert array value in cake php

I have define array value in multiple select value drop down but when we submit the form it is showing multiple array value error.
Please advice.
Use the serialize() function to serialize all the inputs in one value
$this->request->data['Model']['multiple'] = serialize($this->request->data('Model.multiple'));
and if you want to retrieve data use unserialize() to get your array as it saved .
For this purpose I do array_implode in the beforeValidate function, and array_explode in the afterFind function.

SmartGWT Dynamic Form edit record with boolean values

I've got following problem using SmartGWT 2.4:
we are having a DynamicForm showing several static text fields (so the form is in readonly mode). The form uses a datasource in the background and our own FormItemFactory to create proper form items based on our meta data. Some of the form items contain boolean values displayed as strings: like 'isHidden': false or 'canShow': true.
by user action (button click) we need to switch the form to edit mode.
We do it in following way:
we first gather the form values as rec = form.getValuesAsRecord() getting a Record object
then we create a new dynamic form and set into it the same datasource as original has
then we call the newForm.editRecord(rec) method of newly created dynamic form
This way the form static values are shown as editable input fields. However the problem is with those boolean values. They are correctly transformed into check boxes but all of them are checked by default.
I think that the string values 'false' or 'true' are not parsed into boolean values and set as value for respective check box item.
Can I somehow influence this process? I tried to provide an anonymous implementation of FormItemValueParser to CheckboxItem but it turns out to be use only by free text form items.
I'll be really thankful for any given hint.
Try setting the value explicitly to the formItem with record.getAttributeAsBoolean("formItemName")
BooleanItem boolItem = new BooleanItem("boolname");
DynamicForm form = new DynamicForm();
form.setItems(boolItem);
//Get record
Record rec = form.getValuesAsRecord();
boolItem.setValue("boolname",rec.getAttributeAsBoolean("boolname"));

Resources