While I try to stay away from javascript validation, sometimes security concerns get trumped by "quick and dirty." Such is the case when you need simple, conditional validation on forms in SharePoint. Logic like "if Due Date is not NULL then make Justification required." This was the example used in the question from STP today.
As usual, I was onto the solution when someone’s blog straight up answered it for me. Thanks to Edin Kapic for posting his date logic soluton. So far this only works while the "Justification" field is a Plain text field. I had too much trouble getting the RTF field to properly identify any attributes I could use the logic portion. If someone else can get it to work with an RTF field, please drop me a line or post on EndUserSharePoint.com.
<script type="text/javascript">
function PreSaveAction()
{
var findDate = getTagFromIdentifierAndTitle("input","DateTimeFieldDate","Due Date");
var findText = getTagFromIdentifierAndTitle("textarea","","Test");
if(findDate.value != "" && findText.value == "")
{
alert("You must provide a Justification for the Due Date");
return false; // Cancel the item save process
}
return true; // OK to proceed with the save item
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length – len)) {
return tags[i];
}
}
return null;
}
//–>
</script>
I’m not sure if this helps (since it is server side) with your RTF question, but I did some fun things with list forms and needed to check in certain situations if RTF fields had values. My problem was finding out that the value in the RTF field was not null but had an empty div tag or a div tag with a non-breaking space. Not sure if that would be similar with javascript, but it’s a thought.
I did mine in inline C# on the list form replacing the OK button with my own ASP button.
string redirectUrl ="/eIPN/ProcessAction.aspx?Action=SubmitSummary&eIPN=" + SPContext.GetContext(this.Context).Item["eIPN_x0020_Number"].ToString();
SPContext.GetContext(this.Context).Item.Update();
SPListItem item = (SPListItem)SPContext.Current.Item;
bool validated = false;
if(item["InnovationDiscussed"].ToString() == "Yes") { if(item["_x0051_1"].ToString() != "<div></div>" && item["_x0051_1"].ToString() != "<div> </div>")
{
validated = true;
}
if(validated) { Response.Redirect(redirectUrl); }
I also noticed the <div></div> when the page loaded but I couldn’t get both browsers to agree on which element had which value (textarea or input) unless it was not an RTF field. I may have to revisit it again.Thanks,Paul
Making <a href="http://www.rosezuly.com">Rose zuly</a> is the old question : Honestly there is no fast way to make lots of <a href="http://www.rosezuly.com">rose zulie</a> . Sadly enough a lot of the people that all of a sudden come to with millions of <a href="http://www.rosezuly.com">rose online zuly</a> almost overnight probably duped . Although there are a lot of ways to make lots of <a href="http://www.rosezuly.com">rose online zulie</a> here I will tell you all of the ways that I know and what I do to <a href="http://www.rosezuly.com">Arua ROSE zuly</a>.
Nice blog.Thanks for giving good information.<a href="http://www.pass4suresite.com">pass4sure</a>