JavaScript validation in newform.aspx problem

I inherited an app from someone else, built in HTML, CSS and JS inside a content editor web part on a page in SharePoint. Thus far I've been able to extend it and resolve outstanding bugs, but one thing that I have been beating my head against is how the JavaScript validation can be extended to other list forms, as everything I've tried isn't working. It not only conducts validation for a date range (if end date is 3 weeks greater than start date) but also sets the value of a lookup column drop down in the newform.aspx file.

I see the javascript in the js file for the validation, however, it doesn't work on my forms even if I point the js to the .aspx form I created. BUT...If I copy the newform.aspx file from the list that it DOES WORK in to another list where it is needed, with the js file for a new page pointing at that new list and form, the validation triggers, as does setting the value of the drop down menu in the form based on the selection in the javascript based content editor web part app. Only problem is then it's pointing to the lookup values from the original list and not the new one. For example:

Original List is HR. Content editor web part points to a newform.aspx file which has date fields that it conducts validation for, and also sets the value of the lookup column field to the value of whatever you clicked on in the CE web part. If the values are HR 1, HR 2, HR3, and you clicked HR 2, it sets the value of the newform.aspx form field to HR 2.

Now, if I create the app for another department in the exact same way, and point the js file to my own newform.aspx file created in what appears to be the same way as the original, the validation and the setting of the drop down menu do not work. The drop down menu does of course show the correct lookup column values, but the autset feature doesn't work.

But if I now swap the newform.aspx file from the list that it does work in to the new list via SharePoint Designer, the valudation and lookup automation works, but with the values of the original list. For this list they should be OPS 1, OPS 2, OPS 3, but they still look to HR 1, HR 2, HR 3.

There is no custom js in a content editor web part in the page of the newform.aspx file that is doing this. From what I can tell, it's all in the js file for the app that is conducting this function of validation, etc. Still no difference. I'm banging my head against this without any resolution. I even tried creating a new content type the same way the original one was created and I still get the same result. The values of the loopup column from the original list, not my new list if I copy the newform.aspx form over, or if I create a new one, I get the right values but none of the js automation or validation.

September 4th, 2015 3:52pm

I just realized that perhaps the newform.aspx from list A is still pointing to list A even when copied to list B. I'm going to try editing the listid and name info in the file after copying to a new list and see if that works. I've done something similar for workflows in the past and it worked. That's probaly the issue.
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2015 4:42pm

Updating the list guid was part of the solution. There turned out to be a separate hidden file that was being referenced via a content editor web part on the new form page. This web part appears to be hidden via designer properties in the original newform that I was copying over, but when I edited the newform page via the ribbon I could see the web part and it was referencing a js file with the JavaScript for this function. I love working on other peoples stuff...

September 4th, 2015 7:11pm

Updating the list guid was part of the solution. There turned out to be a separate hidden file that was being referenced via a content editor web part on the new form page. This web part appears to be hidden via designer properties in the original newform that I was copying over, but when I edited the newform page via the ribbon I could see the web part and it was referencing a js file with the JavaScript for this function. I love working on other peoples stuff...

  • Edited by techieplaya Saturday, September 05, 2015 12:25 AM
  • Marked as answer by techieplaya Saturday, September 05, 2015 12:25 AM
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2015 11:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics