Fixed value for Form Field

Forums Dynamic Forms for SharePoint Fixed value for Form Field

This topic contains 4 replies, has 2 voices, and was last updated by  B.Sanchez 3 weeks, 4 days ago.

  • Author
    Posts
  • #26363

    B.Sanchez
    Participant

    I have three fields I need to displace as no more 4 decimal places in the form. The field names are CurrentResult1moprior, CurrentResult2moprior and CurrentResult3moprior This are text fields due to Cascading Dropdowns so I assume I have to first convert to number. I’m trying may code snippets found on this forum but none have helped. Here is the last one used:

    
    
    function convertresult(){
      var Result2mo = getFieldValue("CurrentResult2moprior");
      if(!isNaN(Result2mo)){
            var resultValueFixed = Number(Result2mo).toFixed(4);
        setFieldValue("CurrentResult2moprior",resultValueFixed);
      }
    }
  • #26383

    Alexander Bautz
    Keymaster

    I’m not sure I understand exactly, but if you want to ensure the user types in the correct format you can use something like this:

    jQuery("#dffs_CurrentResult2moprior input").on("blur",function(e){
        var str = jQuery(this).val().replace(/[^0-9.]/g, '');
        jQuery(this).val(Number(str).toFixed(4));
    });

    Alexander

  • #26400

    B.Sanchez
    Participant

    OMGeee that is not what I was looking for by I am floored. Wow!!! thank you! I have added this to the form as it will be VERY handy. My original question was for a field that will already have read-only data already pre-populated for them using cascade dropdowns. I just need that pre-populated result to not be longer than 4 decimal places at most.

  • #26404

    Alexander Bautz
    Keymaster

    I see. There is no built in function for manipulating the values in a cascading dropdown – if you use a number column it will by default show 10 decimal because it this this way it is stored in the DB.

    I think the easiest would be to create calculated columns in the source list to set the correct format of the field there – and then use the calculated fields in your cascading dropdown config.

    Alexander

  • #26407

    B.Sanchez
    Participant

    I will do that. Thanks again Alexander!

You must be logged in to reply to this topic.