0

i have an HTML template stored in SQL. As follows

 <label> Date Of Birth
<input type="text" name="txtDateOfBirth" id="txtDateOfBirth" class="" value="{{>~formatDateTime(DateOfBirth,"yyyy/MM/dd")}}" valtype="required" /> </label>

so the above works fine when i actually have a DateofBirth value. But sometimes when the date of birth is NULL it throws the Cannot read property 'indexOf' of null. (because of no data)

my question is in this statement

{{>~formatDateTime(DateOfBirth,"yyyy/MM/dd")}} 

how can i check if the DateOfBirth is NULL then dont do anything if its not NULL then proceeed to format the date

  • you mean `if (DateOfBirth) formatDateTime...` ? – Hollyol Oct 14 '20 at 14:07
  • 1
    Does this answer your question? [Is there a standard function to check for null, undefined, or blank variables in JavaScript?](https://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in) – Hollyol Oct 14 '20 at 14:09
  • @Hollyol i know how to check it in javascript,i just dont know how to structure it in the html context {{>~formatDateTime(DateOfBirth,'YYYY-MM-DD')}} in my sql template –  Oct 14 '20 at 14:13
  • My bad, but it looks like javascript (the `formatDateTime` part) to me. Do you use some library or some rendering engine ? I can't reproduce the error. (gives me a plain string) – Hollyol Oct 14 '20 at 14:38
  • @Hollyol i have a formatDateTime function that is used in the website,but i cant change that function cause i wont know what else would break. i tried something like this in the html value=if(DateOfBirth){{>~formatDateTime(DateOfBirth,"yyyy/MM/dd")}} but it still returns indexof null,cause its not getting ignored –  Oct 14 '20 at 14:47
  • I just don't understand the syntax you are using: Is {{>~[...]}} used to execute some javascript ? – Hollyol Oct 14 '20 at 14:53
  • yeah,its used to hit the javascript function formatDatetime –  Oct 14 '20 at 15:29
  • 1
    @Hollyol i figured it out i used value={{if DateOfBirth}}{{>~formatDateTime(DateOfBirth,"yyyy/MM/dd")}} {{/if}} –  Oct 14 '20 at 15:58

0 Answers0