I am trying to create multiple masked input fields. Angular ui-mask looks like the way to go, however, I can't find very good documentation on the utility. I found an example for credit cards that was very nicely done. I would like to implement this feature in almost exactly the same way, but with 1) phone number 2) decimal 3) percentage 4) email 5) currency, such that the fields are dynamically masked as the user types. My question is how would I go about using ui-mask to accomplish these tasks? Or is there a better way to achieve this? Examples or links to documentation would be appreciated
I guess you can find your answer here:
https://github.com/angular-ui/ui-utils/issues/16
As it is explained in the link a dynamic way is that you can get the mask from a scope/controller variable, check the input and change the mask as needed like:
<input type="text" ui-mask="{{mask}}" ng-keyup="onKeyUp()" ng-model="myinput">
$scope.myinput = '';
var defaultMask = '(99) 9999-9999';
$scope.mask = defaultMask;
$scope.onKeyUp = function(){
if ($scope.myinput.slice(0,3) == '119') { // (11) 9 means mobile, or instead, you could use a regex
$scope.mask = '(99) 99999-9999';
} else {
$scope.mask = defaultMask;
}
};
Related
I try to use Google Script Apps (instead of VBA which I am more used to) and managed now to create a loop over different spreadsheets (and not only different sheets in one document) using the forEach function.
(I tried with a for (r=1;r=lastRow; r++) but I did not manage).
It is working now defining the array for the sheetnames manually:
var SheetList = ["17DCu1nyyX4a6zCkkT3RfBSfo-ghoc2fXEX8chlVMv5k", "1rRGQHs_JShPSBIGFCdG6AqXM967JFhdlfQ92cf5ISL8", "1pFDyXgYmvC5gnN5AU5xJ8vGiihwtubcbG2n4LPhPACQ", "1mK_X4Q7ysJQTt8NZoZASBE5zuUllPmmWSJsxu5Dnu9Y", "1FpjIGWTG5_6MMYJF72wvoiBRp_Xlt5BDpzvSZKcsU"]
And then for information the loop:
SheetList.forEach(function(r) {
var thisSpreadsheet = SpreadsheetApp.openById(r)
var thisData = thisSpreadsheet.getSheetByName('Actions').getDataRange()
var values = thisData.getValues();
var toWorksheet = targetSpreadsheetID.getSheetByName(targetWorksheetName);
var last = toWorksheet.getLastRow ()+ 1
var toRange = toWorksheet.getRange(last, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(values);
})
Now I want to create the definition of the array "automatically" out of the spreadsheet 'List' where all spreadsheets which I want to loop are listed in column C.
I tried several ideas, but always failed.
Most optimistic ones were:
var SheetList = targetSpreadsheetID.getSheetByName('List').getRange(2,3,lastRow-2,3).getValues()
And I also tried with the array-function:
var sheetList=Array.apply(targetSpreadsheetID.getSheetByName('List').getRange(2,3,lastRow-2,3))
but all without success.
It should be possible normally in more or less one single line to import the array from the speadsheet to the Google apps scripts?
I would very much appreciate if someone could please give me a hint where my mistake is.
Thank you very much.
Maria
I still did not manage to put the array as I wanted it initially, but now I found a workable solution with the For Loop which I want to share here in case someone is looking for a similar solution (and then finds at least my workaround ;) )
for (i=2; i<lastRow;i++){
var SheetList = targetSpreadsheetID.getSheetByName('List').getRange(i,3).getValues()
Logger.log(SheetList);
var thisSpreadsheet = SpreadsheetApp.openById(SheetList);
... // the rest identical to loop above...
Don't hesitate to add your comments or advice anyhow, but I will mark the question as closed.
Thanks a lot.
Maria
I am currently implementing the multi language support in one of the website which is being implemented in react as front end tool. I am using react-i18next library for the translation of UI literals in the site. But I am not getting how to implement the various validations in the site , because the regex which I shall use in one text area for english language, shall not work with other language (e.g: Japanese). Kindly help me to figure out this.
What kind of validation are we talking about? Could you give some examples?
For most values the language shouldn't matter e.g numbers are all the same. Select options don't depend on the language - use the default language (before translating) to do the validation and only then translate.
For example:
const schema = yup.object().shape({
name: yup.string().required(i18.t("This field is required")),
pin_number: yup.matches(/\d{4}/, t("Is not in correct format"))
});
However if there is validation that is specific to a language, then yes you need to create a separate regex for each of them.
getLanguageSpecificRegex = () => {
let regex;
if (i18n.language === "en") {
regex = "C\d+";
} else (i18n.language === "et") {
regex = "K\d+";
} else {
regex = "\d+";
}
return regex;
}
As well as Regex, there is also date format and number format to consider, but regex is the biggest problem. Step 1 has got to be
i18n your regexes as well as your validation strings
so that you validation against e.g.
new Regex(i18n.t('regexFirstName'))
Instead of against /\w+/
Markup becomes messier if you are using a declarative markup validation framework:
render() {
return (
...
<input name="firstName" regex={new Regex(i18n.t('regexFirstName'))} />
...
)
but if you are setting validation in code then using
new Regex(i18n.t('regexFirstName'))
instead of
/regexLiteral/
is not a problem?
You are looking for the strategy design pattern.
You need to implement different strategies for different languages for your validation.
I need to show last 4 digits phone number on page which i am going to get from API.
Can you please help me? format should be like (XXX)XXX-1234
Can you be more specific.You can use a pipe for formatting it in desired way.
While your question isn't very specific, you might consider using this: Angular
SlicePipe
That way you can get the last 4 digits of the phone number using string indices.
This is more of a javascript answer, but you could create an expression, then use it in your HTML.
$scope.formatPhone = function(phoneNumber) {
if(phoneNumber) {
return '(XXX)XXX-' + phoneNumber.substr(phoneNumber.length - 4);
}
return '';
}
In reactjs I want to display a property.
Normally this isn't really hard to do it, but this time there is a number in the property. And that number depends on how many links the user has added.
This is an example of what my api returns to my react app:
embed_links: ["2"]
embed_links_0_embed_link: ["https://www.url.com"]
embed_links_1_embed_link: ["https://www.url.com"]
The embed_links is an array which says how many urls the user has filled in.
Then you get the urls the user has filled in, and each one has a number in it.
This is where I got stuck. I have tried to display the links with a for loop like this:
let embed_links = this.props.embed_links[0]
for (let i = 0; i < embed_links; i++) {
console.log(this.props.embed_links_[i]_embed_link[0]);
}
But this does not work..
So my question is basically, is there a possibility that you can display properties witch custom variables/numbers in it?
If you are asking access to a dynamical property within your object:
console.log(this.props["embed_links_" + i + "_embed_link"][0]);
Your syntax is wrong, the correct way to write this is as follows:
let embed_links = this.props.embed_links[0]
for (let i = 0; i < embed_links; i++) {
console.log(this.props['embed_links_' + i + '_embed_link][0]);
}
In the example, 'embed_links_' + i + '_embed_link' is the key that you use to select the correct property of object props.
Yes you can use this.props['embed_links_' + i + '_embed_link'][0]
However i would suggest storing your embed links in an array as objects
embed_links_collection: [
{
url:'https://www.url.com',
id: '1'
}
]
This is a cleaner, managable solution - you could also generate your embed_links property as this.props.embed_links_collection.length
You can use for .. in for enumerating this.props properties
So assume I want to implement custom morelikethis(or autosuggest) experience by merging output of two different morelikethis handler configurations.
Pseudo code could look like
class MyMoreLikeThis extends SearchHanlder {
def process(reqBuilder) {
val mlt1 = reBuilder.getComponent("/mlt1");
val mlt2 = reBuilder.getComponent("/mlt2");
val rb1 = reqBuilder.copy()
val rb2 = reqBuilder.copy()
reqBuilder.results = mlt1.process(rb1).getResults ++ mlt1.process(rb2).getResults
}
}
Or probably I can use solrj API to access solr from inside.
How can I do this? Is there better way to do this?
You can refer to the below blog posts that has detailed explanation on how to achieve merging results from different queries similar to the problem that you are talking about,
Custom Search Handler
Idea#1
Custom Search Handler
Idea#2
The blog is authored by a former colleague of mine who has number of years expertise with Search & Information Retrieval.