Javascript Question

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

15 Nov 2017

I've been looking at the documentation for the javascript and there is one example of what I'm trying to do....almost

fd.field('SOPCompl').change(function(){
if(fd.field('SOPCompl').value())
and (fd.field('AreaSOPCo').value(null){
alert('Please, enter an Area Supervisor');
*Set fd.field('SOPcompl') to false
}
});

What is the correctform I should be using when using two If statements? If the SOPCompl field has been change to true and AreaSOPCo is null

I also want the pop message to appear AND the SOPCompl value to be set to unchecked

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

15 Nov 2017

Hello, Roo!
Good question, I would recommend code like this if I understood your intentions correctly:

Code: Select all

fd.field('SOPCompl').change(function(){
    if(fd.field('SOPCompl').value() && fd.field('AreaSOPCo').value()[0] == null){
        alert('Please, enter an Area Supervisor');
        fd.field('SOPCompl').value('0');
  }
});
That's assuming SOPCompl is a Yes/No type field and AreaSOPCo is a People picker field. If not, the code should be different.

Nothing difficult here really, but I do recommend to check out some info on JavaScript, here or here.
And also our information on getting and setting field values here - https://spform.com/javascript-framework ... eld-values

But you don't need to become a JavaScript expert, simply refer to JS and FD documentation, as well as https://stackoverflow.com/ for JS examples when writing your code, makes it easier to avoid common pitfalls.

Another alternative might be to disable SOPCompl field by default if AreaSOPCo is not selected and only make it available if AreaSOPCo is selected. Something like that should work:

Code: Select all

fd.field('AreaSOPCo').control('ready', function() {
  	if (!fd.field('AreaSOPCo').value().length){
  		fd.field('SOPCompl').readonly(true);
  	}
});

fd.field('AreaSOPCo').change(function(){
  if(fd.field('AreaSOPCo').value().length){
  	fd.field('SOPCompl').readonly(false);
  }
  else{
  	fd.field('SOPCompl').readonly(true);
  }
});
Once again, I assume that you are working with Yes/No and boolen field, this code only works for these types of fields. If not, let me know.
And don't be afraid to ask if you have any questions!
Cheers

User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

15 Nov 2017

Hi Nikita
This does the trick to an extent (it doesn't seem to uncheck the SOPCompl check box)

fd.field('SOPCompl').change(function(){
if(fd.field('SOPCompl').value() && fd.field('AreaSOPCo').value()[0] == null){
alert('Please, enter an Area Supervisor');
fd.field('SOPcompl').value('0');
}
});

Thanks for the reference information - I've been looking around for various sources, but the ones you have given look just the thing.

Thanks again for your patience :) and help

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

15 Nov 2017

My bad, poor spelling, just change fd.field('SOPcompl').value('0'); to fd.field('SOPCompl').value('0');
Cheers

User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

15 Nov 2017

Thanks

I had to change it to this:
fd.field('SOPCompl').value(false);
and it worked

Thanks again for your help and the reference material.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

15 Nov 2017

Interesting. But I am glad it works!
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests