Home Analyst Portal
Options

Anyone know how to customize WI form based on data in the viewModel

chelsea_alonsochelsea_alonso Customer IT Monkey ✭
I'm trying to require a field based on content in the viewModel. Something like this in the customspace/ChangeRequest.js file. 
if (pageForm.viewModel.Category.Name == "Urgent") { 
                                                { DataType: "String", PropertyDisplayName: "Reason for Urgency", PropertyName: "ReasonForUrgency", Required: true, },} 

Both ..Category.Name and ReasonForUrgency are custom extensions, but it could be anything, really. I am noticing that the pageForm.viewModel does not appear to be available at load of the ChangeRequest.js file to logic off of. Please let me know if you have any recommendations. 

Best Answer

  • Options
    Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    edited November 2016 Answer ✓
    Put your logic in custom.js, either in

    $(document).ready(function() { **HERE** };


    or

    app.custom.formTasks.add('ChangeRequest', null, function (formObj, viewModel) {
    	formObj.boundReady(function () {
     **HERE**
    });
    });


    That way it will load after the viewModel is loaded. The second way might be the best fit for what you are describing.

    You wouldn't be adding your field (or not)--the fields will be defined in ChangeRequest.js--you would be hiding the fields after they are rendered (or not).

Answers

  • Options
    Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    edited November 2016 Answer ✓
    Put your logic in custom.js, either in

    $(document).ready(function() { **HERE** };


    or

    app.custom.formTasks.add('ChangeRequest', null, function (formObj, viewModel) {
    	formObj.boundReady(function () {
     **HERE**
    });
    });


    That way it will load after the viewModel is loaded. The second way might be the best fit for what you are describing.

    You wouldn't be adding your field (or not)--the fields will be defined in ChangeRequest.js--you would be hiding the fields after they are rendered (or not).
  • Options
    chelsea_alonsochelsea_alonso Customer IT Monkey ✭
    Oh, you're right! customspace/custom.js does load after the viewModel... That makes a lot of sense. Thanks!
  • Options
    chelsea_alonsochelsea_alonso Customer IT Monkey ✭
    edited November 2016
    It doesn't actually look like the pageForm is available in custom.js without registering it as a task. but waiting for $(document).ready does seem to do what i need it to do! Thank you for the help!
  • Options
    Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    There is a difference that I did not call out, and should have:  $(document).ready refers to it as pageForm.viewModel, but app.custom.formTasks.add() can refer to it simply as viewModel since it accepts the object as a parameter with the name viewModel.

    Sorry for any confusion!
Sign In or Register to comment.