Doug
asked on
Field Conditionally Required in Sharepoint Designer 2007
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('t r').hide() ;
$('nobr:contains("Bar")'). closest('t r').hide() ;
#show if Status = Customer
if ($("select[title='Status'] ").val() == "Customer") {
$('nobr:contains("Foo")'). closest('t r').show() ;
$('nobr:contains("Bar")'). closest('t r').show() ;
}
Thank you in advance
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")').
$('nobr:contains("Bar")').
#show if Status = Customer
if ($("select[title='Status']
$('nobr:contains("Foo")').
$('nobr:contains("Bar")').
}
Thank you in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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
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>
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();
}
ASKER
Thanks Ranier for pointing me in the right direction with the link you provided.
Thank you EE!!!!
Thank you EE!!!!
ASKER
Maybe a Moderator can accept my part of the solution as an assist so it can be added to the KB....?
ASKER
I'd like the 2 textboxes to be required when the dropdown shows "Customer Specific"
TY