Skip to main content

Search

sublist validation (date and person field)

Answered

Comments

11 comments

  • Matthias_Walter

    Hi Jelle Dijkstra,

    to validate a sublist in a skybow rich forms you would need to check it before saving using the script below.

     

    Therefore add a "Form Load Action" of type Execute Script and load the moment.js using jQuery.getScript()

     

    Load moment.js

    jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js");

     

    Validate sublist

    In a second step add an Execute Script action to the Save button. The script below is checking User and Date fields for the moment, but of course it can be extended with other types. (don't worry about the moment error in the builder as it's loaded as form load action in the form)

     

    var subLsits = jQuery('.ard-sublist-webpart');
    subLsits.each(function(index, el) {
      var listController = jQuery(el).data('Controller');
      listController.Changes.forEach(function(change){
        var recordId  = change.GetKey();
        change.Data.forEach(function(data){
          var fieldType = data.propType.ID;
          var value = listController.GetRowValue(recordId, data.fieldKey);
          if(fieldType == "SPUser" && value && !value.data.email){
            alert('User is not valid');//or show status
            change.UpdateValidationInfo([{fieldName: data.fieldKey, isValid: false}]);
          }else if(fieldType == "SPDateTime" && value && !moment(value).isValid()){
            alert('date is not valid: ' + value); //or show status
            change.UpdateValidationInfo([{fieldName: data.fieldKey, isValid: false}]);
          }
        });         
      });
    });

    This script is just working using the classic experience.

     

    Thanks Vitaliy Zadorozhniy for helping with the script!

     

     

    Cheers

    Matt

    0
  • JelleD

    Hi Matthias Walter,

     

    I have tested above solution, some remarks:

     

    Person / User Field

    Validation of the Person (User) Field works to good. All entered data, even correct users,  are not allowed.
    I think it is because of the fact that value.data.email is not recognized. 
    Other finding is that once the User field is cleared the validation still throws up the message ('User not valid'). This is strange because no user is assigned.

     

     

     

    Date Field

    For the date field validation a message is show when the date format is not ok, so far so good. But after the message the form saves and the sublist data is (still) not saved.

    Some improvements are needed to get this working properly.

    regards,

    Jelle Dijkstra

    0
  • Matthias_Walter

    Hi Jelle Dijkstra,

    you are right, 1/1/1 seems to be valid for moment.js and SharePoint does not allow to enter dates before 1/1/1900.

    Please use the following as for line 12 in the previous script (please adjust it to your date format):

    }else if(fieldType == "SPDateTime" && value && (!moment(value,"MM/DD/YYYY").isValid() || moment(value,"MM/DD/YYYY") < moment("1/2/1900"))){

     

    How do you manage to enter an invalid user? Are there users in your system without an email address?

    On my environment it works like this, but if I enter an unknown user it is directly removed from the sublist column..

     

    BR Matthias

    0
  • JelleD

    Hi Matthias,

     

    thanks for this addition for the Date Validation. This validation now works as expected.
    Regarding the user validation, it can be that someone enters a name which is mispelled or not in the users list. The validation than works, but once I correct the user name, it keeps warning me that the user is not Ok, while I am sure that the user is there.
    I think the statement below is not correct:

     

    if(fieldType == "SPUser" && value && !value.data.email){
    0
  • Christof

    Hi Jelle Dijkstra,

    can you share a screenshot of the warning when user is not OK after correcting the user?

    Don't get what you mean with this. In my configuration after checking and correcting it, the user is valid.

     

    If you think the statement is not correct, check with console.log(value.data.email); the user value on your tenant in the Console of Developer Tool (F12) while running the script.

    0
  • JelleD

    Hi Christof Nussbaumer,

     

    I got the message "User is not valid".

    First I entered a wrong value "Jelle", this result in a correct message that the user is not valid.

    Afterwards I changed the name to a correct name, but I still get the error.
    (I tried both, lookup the field with the people picker and typing the correct name, both were not validated).

     

     

    Even when I fill in the name right in the first attempt then user is also not validated.

    (FYI first datarow in example above , contains data before having the validation implemented)

     

    Looking at the console the log provide me a value undefined, in both cases the wrong name and the correct name. So It seems the email propery is not retrievable.

     

    ,

    0
  • Christof

    Hi Jelle Dijkstra

    Which version of SharePoint is in use? I see this script is not working for people picker in SP2013...

    0
  • JelleD

    Yes, we ware using SharePoint 2013

    0
  • JelleD

    Any ideas/suggestions/workarounds to get this working in SharePoint 2013?

    0
  • Christof

    Hi Jelle Dijkstra

    The people picker field control in SP2013 is different and not that responsive as the current one. Therefore it would take some more effort to write such a script working for this control (up to a day of development as a colleague estimate).

     

    Since this is a custom script (configuration, not part of the product) it will not get a slot in our product development and I have to refere you to our paid expert services.

    Just write to support@skybow.com to discuss the details.

    0
  • JelleD

    Thanks for your efforts Christof Nussbaumer,

    For now we leave it as it is.

    0

Please sign in to leave a comment.