Jump to content

Custom code that will regulate format of virtual field input as "mm/dd/yyyy" ?


Recommended Posts

I'm looking for a way to format a virtual field as mm/dd/yyyy.

I'm passing the virtual field value to a date field in the subsequent datapage, and I need to enforce the date format. (I have a calendar pop-up option enabled for the virtual field, but I want to also enforce the format if they type in the date).

Caspio support confirmed this is not a standard feature and would require custom coding (for which they suggested I come here:)

Anybody know how this can be done? Thank you in advance:)

Link to comment
Share on other sites

You can use the code below in your submission page to cast input:

<script>
 document.getElementById('Submit').onmouseover = function (){
var mydate = document.getElementById('InsertRecordDate').value;
var date = new Date(mydate);
var day = date.getDate(); 
var month = date.getMonth()+1; 

document.getElementById('InsertRecordDate').value = (month.toString().length === 1 ? "0" + month : month) + '/' + (day.toString().length === 1 ? "0" + day : day)   + '/' +  date.getFullYear() 




}
</script>

Replace Date in "InsertRecordDate" with your Date Field Name. This code should go to the footer of the page in Source mode.

Link to comment
Share on other sites

  • 1 month later...

Thanks for your response May :)

I've tried your script but I'm not seeing any change in behavior in my application...

If you have time to look at this more, here's some clarification:

I'm using two datapages -- 

  1. First datapage collects training class info.
    (example data: Ladder Safety, 08/19/2017)
     
  2. Second datapage allows user to select names from a list of employees and (by clicking "add" one by one) add them (with class info) into a training attendance records table.
    (example data: John Smith, Ladder Safety, 08/19/2017; Mark Jones, Ladder Safety, 08/19/2017; etc.)

In the first datapage, the fields are virtual, and then passed on to the next datapage (where they are hidden but preloaded for every employee name selected)

Ultimately I really want to be able to prevent the user from progressing to the second datapage if the date on the first datapage was entered in the incorrect format.

I tried using your script on both datapages with no success... (I put it in the footer [source mode], and tried using both "InsertRecordVirtual1" and "InsertRecordClass_Date" as the date field references).

Any other suggestions? Did I use your script correctly?

Thanks a lot for your time.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...