Reputation: 109
I have a panel form in ExtJS and a textfield inside and I am trying to insert a .
symbol before *
in this textfield. I have a button that sends the value from this textfield to a server and returns me results.
In my code, I check if a string contains a *
symbol, then I insert the .
from this textfield into it.
Example of what I have now: I type in textfield *test*
my code convert it to *test.*
. What I need is .*test.*
.
If I type in textfield *t*st*
I need the .*t.*st.*
as a result.
How I can insert the .
symbol before every *
symbol in my value string?
fieldLabel: 'name',
name: 'name',
submitValue: true,
enableKeyEvents: true,
getSubmitValue: function () {
var value = this.getValue();
var format = /[*]+/;
let valTrimmed = value.slice(0, value.length -1);
var ts = '';
if(format.test(value)){
ts = valTrimmed + '.*';
return ts;
}
return value;
}
Upvotes: 2
Views: 426
Reputation: 626929
It appears you can simply replace each *
with itself and a .
in front using
getSubmitValue: function () {
return this.getValue().replace(/\*/g, '.$&');
}
Note that /\*/g
regex matches all occurrences of *
(escaped, since it is a special regex metacharacter) and the $&
in the replacement pattern refers to the whole match.
Upvotes: 2