Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Field Conditionally Required in Sharepoint Designer 2007

Posted on 2013-05-26
6
Medium Priority
?
1,206 Views
Last Modified: 2013-05-31
1. I'm having a problem trying to make 2 fields visible and required only when a dropdown is "Customer"
2. And an opposite condition where one field is required\visible when
     fieldX = Foo,
          and
     fieldY=Bar

I'm running Sharepoint 2007 but it has to work with WSS3
I'm not using Infopath

I got the visibility thing down to this
#hide by default
        $('nobr:contains("Foo")').closest('tr').hide();
        $('nobr:contains("Bar")').closest('tr').hide();
#show if Status = Customer
  if ($("select[title='Status']").val() == "Customer") {
        $('nobr:contains("Foo")').closest('tr').show();
        $('nobr:contains("Bar")').closest('tr').show();
  }

Thank you in advance
0
Comment
Question by:skipper68
  • 4
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39198085
Hi,
I think this post should help
http://sharepointchronicles.com/2011/11/using-jquery-to-simplify-your-forms/

The important step is to override/create the Javascript function PreSaveAction to check the fields before saving to the list.

HTH
Rainer
0
 
LVL 9

Author Comment

by:skipper68
ID: 39199854
Thanks Ranier but I'm having a little difficulty.  This is my first jQuery project.  I've setup a jsFiddle area maybe you can help me with.  

I'd like the 2 textboxes to be required when the dropdown shows "Customer Specific"

TY
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39211817
Hi,
the issue is that your jsFiddle has incomplete HTML (no need of body or html tag), there are missing the table structure as well as the nobr.
If you could attach the HTML output (meaning IE -> View source) of your SharePoint page, I might be able to simulate that in a jsFiddle example.
Thanks.
KR
Rainer
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 9

Author Comment

by:skipper68
ID: 39211855
I figured it out this way.  I hope this saves someone else the hours it took me to figure out.  

After placing the respective html
<!--Place the asterisk html next to the label and the error message tag after the field itself-->
<span class="ms-formvalidation"> *</span>
<span class="ms-formvalidation">You must specify a value for this required field.</span>

Open in new window

In the jQuery section
$(document).ready(function () {
var customerNumberAstrisk = $("input[title='Customer Number']").closest("tr").children("td").first().children("span.ms-formvalidation");
var customerPriceAstrisk = $("input[title='Customer Price']").closest("tr").children("td").first().children("span.ms-formvalidation");
var customerNumberAstriskDetail = $("input[title='Customer Number']").closest("tr").children("td").first().next().children("span.ms-formvalidation");
var customerPriceAstriskDetail = $("input[title='Customer Price']").closest("tr").children("td").first().next().children("span.ms-formvalidation");

//Hide the 4 span items by default
customerNumberAstrisk.hide();
customerPriceAstrisk.hide();
customerNumberAstriskDetail.hide();
customerPriceAstriskDetail.hide();

var inputs = $("input");

//Whenever the Pricing Type field changes…
$("select[title='Pricing Type']").change(function () {
var i = $(this).val();
if (i == "1") {
customerNumberAstrisk.show();
customerPriceAstrisk.show();
} else {
customerNumberAstrisk.hide();
customerPriceAstrisk.hide();
}
});
});

function validateFields() {
var result = true;
var inputs = $("input");
var customerNumberAstriskDetail = $("input[title='Customer Number']").closest("tr").children("td").first().next().children("span.ms-formvalidation");
var customerPriceAstriskDetail = $("input[title='Customer Price']").closest("tr").children("td").first().next().children("span.ms-formvalidation");
sltStatus = $("select[title='Pricing Type']");
if (sltStatus.val() == "1") {
var $CustNum = inputs.filter("[title='Customer Number']").val();
var $CustPrice = inputs.filter("[title='Customer Price']").val();
if ($CustNum == "") {
customerNumberAstriskDetail.show()
result = false;
} else {
customerNumberAstriskDetail.hide()
}
if ($CustPrice == "") {
customerPriceAstriskDetail.show()
result = false;
} else {
customerPriceAstriskDetail.hide()
}
}
return result;
}
// Probably the most important part.  When submit button in pressed this function, when found, is called by the system before the form is submitted. It returns true by default and submits the form. 
function PreSaveAction() {
// validate fields that may be required based on Project Status
return validateFields();
}

Open in new window

0
 
LVL 9

Author Closing Comment

by:skipper68
ID: 39211856
Thanks Ranier for pointing me in the right direction with the link you provided.

Thank you EE!!!!
0
 
LVL 9

Author Comment

by:skipper68
ID: 39211859
Maybe a Moderator can accept my part of the solution as an assist so it can be added to the KB....?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question