Returning partial text from <xfa.event.newText>

Geckoz100 30-01-2015


I have a short script that populates a box with the content of a few fields in a form that they will then use a file name that they can just paste when they click a Submit button.

So here's the script:

FileNameForSave.rawValue = xfa.event.newText + " " + EventName.rawValue + " " + CityEvent.rawValue + " " + StateEvent.rawValue ;

The xfa.event.newText captures a Date field with slashes in YYYY/MM/DD format, but I don't want it to return the slashes.  Is it possible just to grab the numeric part by getting the YYYY first, then the MM, then the DD?

Thanks for any help.

Mark Solution

Are these answers useful?
Help other community members by marking useful answers as accepted.

Accepted Solutions (0)

Answers (5)

Answers (5)

Geckoz100 02-02-2015

Great, that's exactly what I was looking for.  But I don't know how to incorporate it into the script, which is in the "change" event.  Do I need to assigned the "cleaned" date to a temporary variable and then apply the script?

I figure something like this:

var cleanDate = console.println(xfa.event.newText.replace(/\//g,""));

FileNameForSave.rawValue = cleanDate + " " + EventName.rawValue + " " + CityEvent.rawValue + " " + StateEvent.rawValue ;

P.S.  How do you get your colors to show up in the script in these boxes?


This is just an effect of Designers syntax highligher when it finds a double slash in a regular expression

The code is fine.

You also can use as alternative:

xfa.event.newText.replace(/[\/]/g, "");

Geckoz100 04-02-2015

Hi Bruce,

Thanks for all your responses.  In the first line, everything after the double dashes is getting commented out -- is that correct?



The xfa.event.newText for a date field will come though with a date formatted with the edit pattern.  So assuming your edit pattern is date{YYYY/MM/DD} then you can use;

var cleanDate = xfa.event.newText.replace(/\//g, "");

FileNameForSave.rawValue = cleanDate + " " + EventName.rawValue + " " + CityEvent.rawValue + " " + StateEvent.rawValue;


(or you could put it all in one line).

Under Tools ... Optiosn ... Workspace ... JavaScript Syntax Formatting you can change the font type, size and color, I have used customs text color for Number and String.  Just helps me think about if the value would be better off being a form variable, rather than having literals in multiple places in the form.





If you just want to remove the slashes you can use the replace method;


To get to the individual parts use the split method;

var segments = "YYYY/MM/DD".split("/");

console.println(segments[0]) // year

console.println(segments[1]) // month

console.println(segments[2]) // day