4

On load, I am able to set the text value.

But set value does not work when code is triggered by a dropdown change event. Am sure that dropdown change event had been triggered as function was able to change the text of another single line field.

Sample code:

$(document).ready(function()
{
    var activity = SPUtility.GetField('Going');
    var showOrHide = function()

    {
        var activity = activity.GetValue();
        var DL_sys_time = SPUtility.GetField('Time');

        if (activityVal == 'Yes')
        {
            SPUtility.ShowSPField('Time');
            DL_sys_time.setValue('8pm');
        }
        else
        {
            SPUtility.HideSPField('Time');
            DL_sys_time.setValue('');
        }
    };

    $(activity.Dropdown).on('change',showOrHide);
}
)

I am using SPUtility.js (Vers: 0.14.2) downloaded from http://sputility.codeplex.com/

Realised that there are typo in my code above and amended some parts for troubleshooting:

$(document).ready(function()
{
    var activity = SPUtility.GetField('Going');
    var showOrHide = function()

    {
        var activity = activity.GetValue();
        var DL_sys_time = SPUtility.GetField('Note');

        if (activityVal == 'Yes')
        {
            SPUtility.ShowSPField('Note');
            DL_sys_time.setValue('Yes');
        }
        else
        {
            SPUtility.HideSPField('Note');
            DL_sys_time.setValue('No');
        }
    };

    showOrHide();

    $(activity.Dropdown).on('change',showOrHide);
}
)

So when the form loads, the field 'note' is hidden. When I change the value of 'Going' to "Yes", 'Note' field is shown, but the text shown is "No".

  • when I get the value of the rich textbox, I shows that the value is <div></div>... could it be I need to provide some special formatting when setting the value? – LimCha Dec 21 '16 at 9:29
2

You should be using SPUtility.GetSPField like the following:

var notesField = SPUtility.GetSPField("notes");
notesField.setValue("anything"); //this works on multilines of rich text field

From what I've seen in your code, if you're trying to set a date field, it will depend on the formatting, if it's a Date format, you can set the value for it using:

var dateField = SPUtility.GetSPField("DateField");
dateField.SetDate(2016,12,01);

If it's a DateTime, you can do the code above and add the following to set the time:

dateField.SetTime(10,25); //parameters (hour, minute) where 0 < hour < 23
  • Hi, SPUtility.GetSPField – LimCha Dec 21 '16 at 6:32
  • Sorry, GetField() was my typo when typing out the sample codes. I was using SPUtility.GetSPField. Pls see my amended code, I run the function during form load. Seems like it is working during form load, but not when it is triggered by the dropdownlist event. – LimCha Dec 21 '16 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.