Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.
Nível 1
Nível 2
Faça login na Comunidade
Faça logon para exibir todas as medalhas
Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.
Hi - did you ever get an answer for this - to prevent users from entering text into a date field and using ONLY the calendar?
Regards,
B.
Visualizações
respostas
Total de curtidas
Can you cut out all entry ability except calendar? I have hundreds of people entering the days in many ways which is messing up the field.
Visualizações
respostas
Total de curtidas
Visualizações
respostas
Total de curtidas
Visualizações
respostas
Total de curtidas
One of the useful ways I found out to validate the date is using the small script below:
Write this in the validate method:
var d1 = util.scand("yyyy-mm-dd", this.rawValue);
if ( d1 == null ){
this.rawValue = "";
}
Visualizações
respostas
Total de curtidas
I've gotten some great help from others who helped me put together this great script. Put it in the Validate event of your date field. Remember to disable all validation from the Object pallet Patterns button. The script allows the user to type only numbers and populates the slashes automatically. Change the order the the mmddyyyy masks throughout, as needed. I've been using this in many forms, works like a charm.
//Custom Date Validation Java Script for entering dates using numbers only
//With assistance from Ricardo Falegnami and BR001
// adding slashes
var newDate = this.rawValue;
// validate date
if (newDate !== null)
{ // process non-empty string
var oMyDate = [];
oMyDate[0] = util.scand("mmddyyyy", newDate);
oMyDate[1] = util.scand("mddyyyy", newDate);
oMyDate[2] = util.scand("mmdyyyy", newDate);
oMyDate[3] = util.scand("mdyyyy", newDate);
oMyDate[4] = util.scand("mmddyy", newDate);
oMyDate[5] = util.scand("mdyy", newDate);
var isDate = false;
for (var i=0; i < oMyDate.length; i++)
{
if (oMyDate[i] !== null) {
this.rawValue = util.printd("mm/dd/yyyy", oMyDate[i]); // strict format
isDate = true;
break;
}
}
// Stay in field if invalid
if (isDate === false) {
app.alert("Invalid date entered -- please enter in MMDDYYYY format, \n\nfor example, 051920152)", 0, 1, "CHECK DATE FORMAT"); // check validity
xfa.host.setFocus(this)();
}
}
Geckoz100 I really like what your code does, or should do but I cant get it to work.
If paste the code into a custom validation script or even a on blue event for a date field nothing happens.
I watched the value of newDate = this.rawValue but it is always undefined?
What am I missing?
Cheers
-Al
Visualizações
respostas
Total de curtidas
Hi Al,
Just to make sure we're on the same page -- this is for LiveCycle Designer, and the script needs to be in the Validate event of the script. I trimmed the script down to accept only MMDDYYY entry. This way there's no confusion; there were too many other masks. The script works great for me -- the user just has to type numbers and the date is validated and slashes are added automatically upon exiting. Let me know if you have any luck.
var newDate = this.rawValue;
if (newDate !== null) // process non-empty string
{
var isDate = false;
var oMyDate = util.scand("mmddyyyy", newDate);
if (oMyDate !== null) {
this.rawValue = util.printd("mm/dd/yyyy", oMyDate); // strict format, adding slashes
isDate = true;
}
if (isDate === false) { // Stay in field if invalid
app.alert("Invalid date entered -- please enter in MMDDYYYY format, \n\nfor example, 05192016 (no slashes required)", 0, 1, "CHECK DATE FORMAT"); // check validity
this.rawValue = "";
xfa.host.setFocus(this)();
}
}
Visualizações
respostas
Total de curtidas
Well I am doing this in Acrobat, but I don't think that should matter should it?
Acrobat still has a validate event. I have also tried in the "On blur" event.
Visualizações
respostas
Total de curtidas
My issue is that this.rawValue always seems to be empty?
Visualizações
respostas
Total de curtidas
I managed to sort it out using this code:
var fldDate = this.getField("DOB").value;
var strDate = "12122004";
fldDate = fldDate.toString();
app.alert("Field Date is " + fldDate + " and the type is : " + typeof fldDate);
app.alert("String Date is " + strDate + " and the type is : " + typeof strDate);
var fmtDate = util.scand("ddmmyyyy", fldDate);
app.alert("Print this is scand date: " +fmtDate);
app.alert("THis is printd date: " + util.printd("dd/mm/yyyy", fmtDate));
It became apparent that the date (12122004) put into the field was stored as a type "num" and scand needed a string. Once I did the type conversion life was good.
If I was able to us this.rawvalue - the type conversion may not have been a issue?
I am now going to use regexp to limit my users to ddmmyyyy or ddmmyy.
Format like dmmyy are too easy to be interpreted either way.
Regards,
-Al
Visualizações
respostas
Total de curtidas
I thought perhaps the javascript syntax might be a little different in Acrobat vs. LiveCycle. If it's not, that's good to know. But after working in LCD, I never do anything in Acrobat any more.
That type conversion was a smart move; I don't think I could have figured that out. I'm not a very experienced coder. But I don't understand why you were getting nothing from the rawValue; did you ever figure that out? BTW, where is OZ?
Visualizações
respostas
Total de curtidas
One other thing just occurred to me -- perhaps you have the script in a Date field. I used a text field, so that I could run my own script without interference from any automated functions in the Date Field object type. I don't know if that might make any difference with the type conversion issue.
Visualizações
respostas
Total de curtidas
Visualizações
Curtida
respostas
Visualizações
Curtida
respostas
Visualizações
Curtida
respostas