Copy link to clipboard
Copied
I would like to create a dynamic stamp something like this, as long as the second field contain "B" then the first and second field text will change to colour blue or if contain "O" then will be colour orange.
is there anyone can give me some advise how to achieve this goal, since I am very green in Javascript.
many thanks
ado
No. To check for that use:
if (/o/i.test(cMsg))
Copy link to clipboard
Copied
Were you able to create a dynamic stamp that does all of it, except for the coloring? If so, how is the user inputting the values of the fields?
Copy link to clipboard
Copied
Also, your question is not very clear... Are you trying to change the color in the app.response window, or in the stamp itself?
The former is not possible.
Copy link to clipboard
Copied
just the stamp text change colour
thanks
Copy link to clipboard
Copied
this are my stamp script
first field:
var cAsk = "input sh" ;
var cTitle = "Table";
if(event.source.forReal && (event.source.stampName == "#Ao-bX_USVdL6_dk0gBSz6C"))
{
var cMsg = app.response(cAsk, cTitle);
event.source.source.info.exhibit = cMsg;
}
second field:
var cAsk = "input colour code" ;
var cTitle = "Table";
if(event.source.forReal && (event.source.stampName == "#Ao-bX_USVdL6_dk0gBSz6C"))
{
var cMsg = app.response(cAsk, cTitle);
event.source.source.info.exhibit = cMsg;
}
after input the colour code "B" the stamp colour will change to colour blue, the first field also change to blue, just like the picture I attached in the post.
many thanks
Copy link to clipboard
Copied
Where does you fill the form fields?
Copy link to clipboard
Copied
first field will be on "1"
second field will be on "B"
Copy link to clipboard
Copied
Yes, but in the code you posted the value is never copies to the field...
Copy link to clipboard
Copied
sorry I do not understanding what you mean?
Copy link to clipboard
Copied
The code you posted will populate any field. You left out the command that does so.
It would be something like:
event.value = cMsg;
Copy link to clipboard
Copied
yes, I created the stamp,but I just don't know how to change the colour for the text
thanks for your help
Copy link to clipboard
Copied
yes you right I missing statement,
the correct one is follow:-
first field
var cAsk = "input Sh" ;
var cTitle = "Table";
if(event.source.forReal && (event.source.stampName == "#Ao-bX_USVdL6_dk0gBSz6C"))
{
var cMsg = app.response(cAsk, cTitle);
event.value = cMsg;
event.source.source.info.exhibit = cMsg;
}
second field
var cAsk = "input colour code" ;
var cTitle = "Table";
if(event.source.forReal && (event.source.stampName == "#Ao-bX_USVdL6_dk0gBSz6C"))
{
var cMsg = app.response(cAsk, cTitle);
event.value = cMsg;
event.source.source.info.exhibit = cMsg;
}
sorry for the confusion. 😞
Copy link to clipboard
Copied
OK, that makes more sense. The next step would be to add something like this to your code:
if (cMsg=="O") event.target.textColor = color.yellow;
else if (cMsg=="B") event.target.textColor = color.blue;
else event.target.textColor = color.black;
Copy link to clipboard
Copied
thank you for your reply
will this statement also work for first field, because the second field determent the colour?
thanks
Copy link to clipboard
Copied
That code will only affect the main field, the one triggering the calculate event, but you can easily apply the same for others.
For example:
var otherField = this.getField("Name of other field");
if (cMsg=="O") otherField.textColor = color.yellow;
else if (cMsg=="B") otherField.textColor = color.blue;
otherField.textColor = color.black;
Copy link to clipboard
Copied
thank you
what if the cMsg just contain "o", because may input O1, or O2... would cMsg== "O" work?
thanks again
Copy link to clipboard
Copied
No. To check for that use:
if (/o/i.test(cMsg))
Copy link to clipboard
Copied
WOW !! Thank you so much it work so good, this is exactly what i am look for.
thank you for helping me to achieve this goal and I learn alot too
Copy link to clipboard
Copied
The first field I can not get it to work
var cAsk = "input Sh" ;
var cTitle = "Table";
if(event.source.forReal && (event.source.stampName == "#JwM0QVfkrXapNXl01OFT1C"))
{
var cMsg = app.response(cAsk, cTitle);
event.value = cMsg;
var otherField = this.getField("second");
if (cMsg=="r") otherField.textColor = color.red;
else otherField.textColor = color.black;
event.source.source.info.exhibit = cMsg;
}