Unable to set Read-Only Date field with spjs.utility.setDateFieldFromDateObject

Home Forums Classic DFFS Unable to set Read-Only Date field with spjs.utility.setDateFieldFromDateObject

Viewing 2 reply threads
  • Author
    Posts
    • #33723
      Brent Caudill
      Participant

        Hi Alexander,

        I am using the JS below to set a date field. The code is working as expected if I leave the date field as Editable in Rules, but if I set it as Read-Only with a rule when the form is initiated the code isn’t updating the field.

        I am triggering the doCalculateDates function when the ‘Advance 1 Date’ field is changed.

        I was using a DFFS version from a month or two ago, but just updated to the most recent version as of today (v4.4.5.26 – May 27, 2021|CSS version: 4.51 / |spjs-utility version: 1.351).

        
        
        function dateOffsetDays(date, days){
            var d = new Date(date.valueOf());
            var nDate = d.setDate(d.getDate()+days);
            return new Date(nDate);
        }
        
        function doCalculateDates(){
            var advanceDate = spjs.utility.getDateFieldAsDateObject("Advance1Date");
            console.log(advanceDate);
            var bterm = parseFloat(jQuery("input[title='Base Term']").val().replace(/,/g, '')) || 0; 
            console.log(bterm);
            var maturedays = bterm * 365;
            console.log(maturedays);
            var plusDays = dateOffsetDays(advanceDate, maturedays);
            console.log(plusDays);
            spjs.utility.setDateFieldFromDateObject("MaturityDate", plusDays);
        }
      • #33728
        Alexander Bautz
        Keymaster

          Hi,
          The actual value is set, but the readonly display value is not updated. I’ll look into fixing this in the next version, but you can work around it by just adding these two lines at the bottom of your custom function:

          spjs.dffs.undoReadOnly(["MaturityDate"]);
          spjs.dffs.doReadOnly(["MaturityDate"]);

          Alexander

        • #33739
          Brent Caudill
          Participant

            Thanks for the fast response Alexander! The work around is doing the trick.

            Thanks again!

            Brent

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.