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]
Related
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
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
I am using react table. I am calling a method on API (.NET), which concatenates some fields and now I need to display this concatenated field in react table column.
From API I tried to put /n in the column so that it renders a new line on UI (inside react table). But no luck. Example: I need to display
This field is calculated by adding two numbers 10 and 20. Since the
result is greater than 15 you cannot perform this operation.
In the displayed text, what I want is "Since" should start in a new line in react table.
I tried to put {'\n'} before "Since" but it did not work. Any ideas how to achieve this?
The '\n' escape character does not work in HTML. You have to work with
other HTML solutions like using <br> or divs to get a multiline
implementation working.
You solve this quite easily. when getting the string append a special char like the comma (,) or some other char that you are sure would not be used in your original text.
Then get that string to a js variable in your react app.
let multiLineString = "This field is calculated by adding two numbers 10 and 20. , Since the result is greater than 15 you cannot perform this operation";
let lines = multiLineString.split(',')
let linesHTML = lines.map((line)=><div>{line}</div>);
now render this variable anywhere you want, you will get a multi line string implementation.
Of course the better approach would be to get a json array of values from the back end.
Anyone knows how to get list of selected CheckBoxList values from Umbraco using ContentService?
I use contentService.GetValue("currencies")
and I get string with numbers and commas something like "154,155,156,157"
How can I get actual values?
Does anyone know how to do it using DataTypeService?
As it was mentioned above, you can use Umbraco helpers method to retrieve string value for the PreValue id.
Umbraco.GetPreValueAsString([PreValueId])
You can find more about it here: https://our.umbraco.org/documentation/reference/querying/umbracohelper/#getprevalueasstring-int-prevalueid
It's calling database directly through the DataTypeService behind the scene. It's worth to reconsider it and close it on another type of property / data type to avoid calling database on the frontend layer and just retrieve data from IPublishedContent cached model.
Read also about common pitfalls and anti-patterns in Umbraco: https://our.umbraco.org/documentation/Reference/Common-Pitfalls/
Those are prevalues.
From that given string, you have to split those and get the real value by calling one of umbraco library umbraco.library.GetPreValueAsString(123);
For example.
foreach(var item in contentService.GetValue("currencies").Split(',')) {
var realValue = umbraco.library.GetPreValueAsString(int.Parse(item);
}
You have 2 nulls because prevalues sometimes has blank values on it, like "121,56,,15,145".
You need then to modify your split code like this
foreach (var item in value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
}
StringSplitOptions.RemoveEmptyEntries will ignore empty spaces.
I am trying to get a value from salesforce class into a javascript variable. I am able to get the value if its a single line value, but if its multiline textarea it gives a unterminated string literal error
caseUpdate.Description = "{!ac__c.C_Info__c}";
After googling for sometime i came to know we can have a workaround for this by having a hidden field and using DOM storing it using the document.getElement.Id. But i am calling this code on a button click so i would not be able to create a input text or hidden field value.
Any body who can provide an way to do it?
Thanks
Prady
You should just be able to use the standard Salesforce JSENCODE() function if you are using OnClick Javascript in a button. This will escape any characters for you.
See the documentation.
It is because of line breaks. merge fields are rendered unescaped into the output stream meaning that CRLFs push into a new line and break javascript strings. Either use the div/input trick or use Apex to replace \r\n's in the field with <br/> or whatever best suits the purpose. Also keep in mind that " will also terminate your JS string.
The easiest way is to just include a function in your extension and then you can use it across board
public String FixNewLine(String s) {
if (s != null) return s.replaceAll('\r\n', '<br/>').replaceAll('"', '\\"');
return null;
}
I had the same issue but was able to fix it! The trick is the JSENCODE function. Its basically {!JSENCODE(Obj.Field)}"; So you are replacing your merge field with this function and nesting the merge field itself within the function. In my scenario I ended up with opptyObj.Description="{!JSENCODE(Case.Description)}"; as my total syntax. First calling upon my set object and field, and then the merge data to populate it.