Jump to content
  • 0

First Day of the month


NeoInJS

Question

6 answers to this question

Recommended Posts

  • 0

Hi @NeoInJS,

 

Having the date field default to first day of the month, and have the field be editable at the same time is currently not possible in Submission Forms without JavaScript customization.

 

Too keep things simple in cases of "editable-default" value , I usually just setup a Virtual Field that is a placeholder of the custom user-input value, then have a Calculated Value for the actual field to be either the "user-input value", or the default value if it is blank.

 

You may do so by following these instructions:

1.) Create a Virtual Field that will hold the user-input values. (I would suggest creating a not for your users that say "Defaults to first day of the month").

2.) For the actual date/time field, you may set the Form Element to a "Calculated Value", then use the syntax below (For this example, I assumed that you use Virtual 1 as your placeholder):

CASE WHEN DATALENGTH('[@cbParamVirtual1]') > 0

THEN
TRY_CONVERT(date, '[@cbParamVirtual1]')

ELSE
DateAdd(
  day,
  1 - DatePart(day, '[@cbTimestamp*]'),
  '[@cbTimestamp*]'
)

END

 

Hope this helps.

 

-DN31337

 

Link to comment
Share on other sites

  • 0
17 hours ago, NeoInJS said:

Thank @WatashiwaJin. However, I would still like my users to be able to change the field. I want to see that field populated with the First day of the month when the DataPage loads.

Hi @NeoInJS -- if that is the case then I suggest that you follow these steps:

- Add a "Virtual field" that uses "Calculated value" as the form element and paste the formula:
 

CONVERT(DATETIME, (CAST(Month(SysUTCDateTime()) AS VARCHAR) + "/01/" + CAST(Year(SysUTCDateTime()) AS VARCHAR)), 101)

- You can also hide the Virtual field -> go to the advance option then check "Hide Field:
image.png.c9bc0467af08bfcd8ca06891638251c4.png

- Now, we are going to create a script that will get the value form the formula. For us to do that we need to add a "Header and Footer" -> then in the footer paste this code:
 

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 
  var vrt = document.querySelector('[name*=cbParamVirtual1]');
  var date = document.querySelector('[name*=InsertRecordYOURDATEFIELD]');
 
  vrt.onchange = function() {
  date.value = this.value.substring(0,9);
  }
  });
</script>

- Make sure that you unchecked the "Enable HTML Editor" in the advance tab of the Footer.

- After this process, your date field will get the first day of the month and it still can be editable :)

 

For more details, check these article:

https://howto.caspio.com/function-reference/

https://howto.caspio.com/datapages/ajax-loading/

I hope this helps :) 

~WatashiwaJin~

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
Answer this question...

×   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...