How to exclude a field from spellcheck in sharepoint 2010? - sharepoint-2010

I have a SharePointWebControls:UserField in a page layout that needs to be excluded from spell checking, as otherwise whenever a user is selected there are a large number of spelling errors are detected in the code-behind for the control.
It seems that in Sharepoint 2007 this behaviour could be implemented by using excludefromspellcheck = "true" but this doesn't seem to work for Sharepoint 2010. Has anyone come across the same problem and found a way around it?

Based on SpellCheckEntirePage.js, that appears to still be the way:
var elements=document.body.getElementsByTagName("*");
for (index=0; index < elements.length;++index)
{
if (null !=elements[index].getAttribute("excludeFromSpellCheck"))
{
continue;
}
// snipped - if (elements[index].tagName=="INPUT")
// snipped - else if (elements[index].tagName=="TEXTAREA")
}
But excludeFromSpellCheck is not a property of UserField, so it probably won't automatically copy down to the rendered HTML. When rendered, the UserField control is made up of several elements. I would try looking at the View Source to see if excludeFromSpellCheck is making it into the final HTML. But to set the attribute on the appropriate elements, you might need to use some jQuery like this:
$("(input|textarea)[id*='UserField']").attr("excludeFromSpellCheck", "true");

You can disable the spell check for certain fields by setting the "excludeContentFromSpellCheck" attribute to "true" on text area and input controls that you dont want to be spell checked.
I did this on all my page layouts. Now i dont get false positives anymore.
The solution is to add a div tag around the fields you don't want spell checked and adding a javascript that sets "excludeFromSpellCheck" to "true" for the elements within the div tag.
The solution i found is described here: Inaccurate Spell Check on SharePoint Publishing Pages

Joe Furner posted this solution, which has worked for me.
https://www.altamiracorp.com/blog/employee-posts/spell-checking-your-custom-lay
It excludes all PeoplePickers on the page:
function disableSpellCheckOnPeoplePickers() {
var elements = document.body.getElementsByTagName("*");
for (index = 0; index < elements.length; index++) {
if (elements[index].tagName == "INPUT" && elements[index].parentNode && elements[index].parentNode.tagName == "SPAN") {
var elem = elements[index];
if (elem.parentNode.getAttribute("NoMatchesText") != "") {
disableSpellCheckOnPeoplePickersAllChildren(elem.parentNode);
}
}
}
}
function disableSpellCheckOnPeoplePickersAllChildren(elem) {
try {
elem.setAttribute("excludeFromSpellCheck", "true");
for (var i = 0; i < elem.childNodes.length; i++) {
disableSpellCheckOnPeoplePickersAllChildren(elem.childNodes[i]);
}
}
catch(e) {
}
}

This code is working partially only,because if you put the people picker value again checking the people picker garbage value for one time.

Related

In Umbraco, how to handle tag datatypes with Examine?

I have made a search page using Examine which for the moment works fine and as intended (still needs to get paging sorted...), but I have run into an issue. I also want the page to function as a related tags page, as in an article can have several tags, and if you click a tag you can see related articles with the same tag. Pretty basic stuff. Only I have found out that Examine cant really handle tag data types because as I understand they are stored in a comma delimited list, something Examine cant handle in this case. I have searched around and found only a few hints of others having the same problem, one with an actual solution but that sadly no longer works in Umbraco 10: Umbraco - Using Examine to search Umbraco.Tags
Also found this more recent one, but kind of a dead end: https://our.umbraco.com/forum/umbraco-8/98761-how-to-match-tags-in-examine-in-v8-theyre-now-stored-as-a-json-string-array
So yeah, what the heck do I do?
For good measure here is my examine code:
#{
Layout = "master.cshtml";
var searchQuery = !string.IsNullOrWhiteSpace(Context.Request.Query["q"].ToString()) ? Context.Request.Query["q"].ToString() : "";
var tags = !string.IsNullOrWhiteSpace(Context.Request.Query["tags"].ToString()) ? Context.Request.Query["tags"].ToString() : "";
var parent = !string.IsNullOrWhiteSpace(Context.Request.Query["parent"].ToString()) ? Convert.ToInt32(Context.Request.Query["parent"].ToString()) : 1088;
if (!examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex index))
{
throw new InvalidOperationException($"No index found by name{Constants.UmbracoIndexes.ExternalIndexName}");
}
var searcher = index.Searcher;
var criteria = searcher.CreateQuery(IndexTypes.Content);
var filter = criteria.ParentId(parent).AndNot(x => x.Field("umbracoNaviHide", 1.ToString()));
if (!string.IsNullOrWhiteSpace(tags))
{
filter.And().Field("tags", tags);
}
if (!string.IsNullOrWhiteSpace(searchQuery))
{
filter.And().ManagedQuery(searchQuery);
}
var res = filter.Execute();
}

IG - how to register changes to cell being edited - eg. to action shortcut key (Oracle Apex Interactive Grid)

We have common functionality across multiple pages: Cancel/Save/Back/Next (buttons).
I added shortcut keys via app-level static JavaScript file: Alt-C/S/B/N (using common CSS on the buttons & jQuery binds).
Problem: when using shortcut key whilst editing a cell, the edits to the cell were not saved with Alt-S, Alt-N. (For same reason, no confirmation requested on Cancel/Back, since the grid did not see any changes.)
Much searching and reading of documentation did not reveal the answer...
After a huge amount of effort: inspecting of widget/ interactiveGrid/ model/ getCurrentView via the console & inspect-panes (partly because I didn't find/inspect the .interactiveGrid('getViews','grid).getColumns() for a long time), I found a solution, but I feel there must be a more elegant one. Advice sought! TIA.
Here is my solution. Note the namespace is lps, and I have aliased apex.jQuery as lps.$ prior to the code below. I include comments for my Oracle colleagues less experienced with JS, Apex, jQuery, etc.
The solution works for all 4 shortcut keys, and should work for any IG (possibly even without a static id on the containing region, although my test case has a static id). There is some supporting code after the main solution. All happening on page load via the static JS file.
The jQuery selectors must only bind to a single button on each page!
lps.$(window).on('keydown',function($evt) // Capture Alt + shortcut key in keydown event
{
// $evt is the jQuery simplified event
if( $evt.altKey ) // the alt-key is being pressed-and-held
{
var key = $evt.key.toUpperCase();
if( lps.shortcuts[key] )
{
if( lps.$($evt.target).is('input,textarea') ) // effect the onchange() JavaScript (more specifically, the IG version thereof)
{
// We've pressed a shortcut key combo, whilst editing a cell, so the IG-onchange-y event hasn't yet fired
var tgtEle = $evt.target,
newVal = tgtEle.value, // the value of the on-screen element, regardless of change-status
tgtId = tgtEle.id, // this tallies with an elementId exposed via the igCols below
activeFld;
// IG stuff - igId - get the IG overall id via an IG ancestor div of the target field, then losing the trailing _ig suffix
var igId = lps.$(tgtEle).parents('div.a-IG')[0].id.replace(/_ig$/,'')
igWidget= apex.region(igId).widget(),
igGrid = igWidget.interactiveGrid('getViews','grid'),
igModel = igGrid.model,
igView = igWidget.interactiveGrid('getCurrentView'),
igRecId = igView.getActiveRecordId(),
igCols = igGrid.getColumns(); // this provides meta information about the columns in the IG
for( var i=-1; ++i<igCols.length; ) // find the field name of this IG-column from target element id
{
if( igCols[i].elementId === tgtId )
{
activeFld = igCols[i].property;
break;
}
}
// Phew. Eventually setValue on the IG-cell so Apex knows the cell has changed without an onchange firing
igModel.setValue(igModel.getRecord(igRecId),activeFld,newVal);
}
$evt.originalEvent.preventDefault(); // we're consuming the event, so stop it doing some native browser trick we don't want
lps.$(lps.shortcuts[key].selector).select(); // select the to-be-clicked-element
lps.$(lps.shortcuts[key].selector).click(); // synthesise a click on the selector'd element
}
}
});
Supporting code to pre-establish what our 4 shortcut keys are to be:
lps.shortcuts = { // keys and their jQuery selectors
B : { selector:'button.nav-back' },
C : { selector:'button.nav-cancel' },
N : { selector:'button.nav-next' },
S : { selector:'button.nav-save' },
};
Code to add hover-title to the buttons:
// Advertise the shortcut with a 'title' attribute (appears as popup tip when hover over the element)
for( var key in lps.shortcuts ){
lps.$(lps.shortcuts[key].selector).attr('title','Alt+'+key);
}

vBulletin 3.x - How to get custom variable to render template conditionals?

I am trying to make a product that will give me a different header based on the forum I am in, that's no problem and complete. My issue lays with using template conditionals inside of said option.
I am currently using a forum option to insert my custom template additions:
In global_complete hook I am using:
global $vbulletin;
if ($GLOBALS[foruminfo]["forumid"]>0) {
$forum_code = '';
$_fid = $GLOBALS[foruminfo]["forumid"];
$forum_info = $vbulletin->forumcache[$_fid];
if ($forum_info["code"]) {
$forum_code = $forum_info["code"];
} elseif ($forum_info["parentid"]) {
while ($forum_code=='' && $forum_info["parentid"]>0) {
$forum_info = $vbulletin->forumcache[$forum_info["parentid"]];
$forum_code = $forum_info["code"];
}
}
}
Then I place $forum_code into my header temple.
I would like to be able to get the conditionals to work so I can only show things to members or usergroups within the header. Is there a way to get the variable to not ignore the conditions? they are included in the DB entry, just being ignored when rendered to the page.
Sample Conditional:
<if condition="$show['member']">Member<else/>Guest</if>
What is actually being rendered:
MemberGuest

Adobe Illustrator Scripting - Change Color of Selection

I'm trying to set the colour of my current selection in Illustrator using a .jsx script.
I can't find documentation on changing styles on (selected) objects. I have read most documentation out there, but I can't seem to find such a "simple" thing anywhere. Here is the code I've come up with:
thisThing = app.activeDocument.selection[0];
thisThing.filled = true;
thisThing.fillColor = '#ff0000';
When I run it, nothing happens sadly.
I have figured out a solution - it works, but it's very messy (due to being an edited solution). This gives a random grey colour to the selected item:
var myGrey= new CMYKColor()
myGrey.black=((Math.random()*80)+10);
if (app.documents.length && app.selection.length)
{
for (var a=0; a<app.selection.length; a++)
{
try {
app.selection[a].fillColor = myGrey;
} catch (e)
{
// ignoring all possible errors ...
}
}
}
In case you want to do non-grayscale: add myGrey.Yellow = value between 1-100;

select2 scroll to error not working with jquery validation and asp.net mvc

Posting this here in case someone else has the same problem...
When using a select2 dropdown in a C# MVC4 site, the page is not scrolled to the correct position when validation fails. Validation as such works and error scrolling also works for other controls, just not select2's. The reason AFAICS is that select2 replaces the original select with it's own markup and then set the original select as display:none. jquery.validate then has no valid target to scroll to.
We are using twitter bootstrap for styling, but I don't think it has any impact on this problem.
The jquery.validate documentation (as well as many answers here on StackOverflow) suggests that you use $.validator.setDefaults to assign the invalidHandler, but I couldn't get this to work in asp.net (it does work for focusInvalid however), probably due to us using the MS unobtrusive library. Instead I used this code in my jquery ready handler:
$(function() {
$.validator.setDefaults({
focusInvalid: false
});
function scrollToError(error, validator) {
var elem = $(validator.errorList[0].element);
if (elem.length) {
if (elem.is(':visible'))
return elem.offset().top - 16;
elem = elem.prev($(".select2-container"));
if (elem.length) {
return elem.offset().top - 16;
}
}
return 0; // scroll to top if all else fails
}
$('form').bind('invalid-form.validate', function(error, validator) {
// fix scrolling and validation for select2
if (!validator.numberOfInvalids())
return;
$('html, body').animate({
scrollTop: scrollToError(error, validator)
}, 500);
});
...
I set focusInvalid to false to disable and avoid conflict with the standard scroll and focus behavior.
The bind() call is used instead of the invalidHandler option and is the same as used by the validate plugin.
scrollToError() selects the first invalid element and returns the position to scroll to, either a normal visible element or a previous item with the 'select2-container' class (i.e a select2 element) or top of page if all else fails.
Standard behavior (showing validation errors etc) still works as before.
Hope this helps someone and if you have a better solution I would be very interested in knowing about it.