SharePoint Publishing HTML Field Control Converts Relative URL to Absolute URL - url

So, after much research on whether or not we should the CEWP or the HTML Field Control on an external facing SharePoint site, we settled on using the Field Control (much thanks to AC). Now, we are having an issue that all the blogs I read say should not be an issue.
When we put a relative URL into the HTML Editor and hit OK, it is automatically changed to an absolute URL. This is apparently a "feature" of Internet Explorer from some of the research I have been doing. TinyMCE has a work around for this. I was wondering if there was some work around for the SharePoint control that I am missing.
This is kind of a big issue for us because we have an authoring site and the www site. So, when the authoring is done on the authoring site and all the links get migrated to the www site, they are http:// authoring.domain.com/en-us/Pages/... instead of /en-us/Pages/...

I encountered this issue as well. We had custom site fields and content types deployed via feature. The RichText property of the HTML Field is properly as true in caml, but once deployed the SPField in the root web fields collection and every Pages list the RichText attribute becomes false.
I was able to successfully resolve the issue by using a feature receiver on the feature that deploys the site columns and content types. My code loops every web in the site and then iterates over the fields to update them.
code snippet:
private void processweb(SPWeb web)
{
SPList list = web.Lists["Pages"];
SPField field;
for (int i = 0; i < list.Fields.Count; i++)
{
field = list.Fields[i];
//to work around a sharepoint defect ... make html fields work in richtext mode
if (field != null && string.Compare(field.TypeAsString, "HTML", true) == 0 && (field as SPFieldMultiLineText).RichText == false)
{
(field as SPFieldMultiLineText).RichText = true;
field.Update(true);
}
}
foreach (SPWeb w in web.Webs)
{
processweb(w);
}
}

Related

Vaadin : How to get Element by ID?

How to get HTML Elmement (or DOM) in Vaadin ?In GWT I can use as DOM.getElementById("myId");
I can set id attribute on my Vaadin components by setId() method. For example:
Button button = new Button("Say Hello");
button.setId("myButton");
So, how can I retrieve this DOM Element in Vaadin ?
You can use this:
public static Component findComponentById(HasComponents root, String id) {
for (Component child : root) {
if (id.equals(child.getId())) {
return child; // found it!
} else if (child instanceof HasComponents) { // recursively go through all children that themselves have children
Component result = findComponentById((HasComponents) child, id);
if (result != null) {
return result;
}
}
}
return null; // none was found
}
Source: https://vaadin.com/forum/#!/thread/3199995/3199994
Vaadin 10 (Vaadin Flow)
The new Vaadin Flow generation replaces the internal use of GWT for Web Components.
This new architecture provides us with easy direct access to the DOM from the Java-based server-side, if you so desire. You can read the DOM, and you can manipulate elements in the DOM. Read about the new Element API in the manual.
Vaadin 6, 7, & 8 (Vaadin Framework)
This Answer expands on the comment by Vaadin expert, Henri Kerola.
Vaadin is a server-side app framework. It's purpose is to shield the app developer from the details of HTML, CSS, JavaScript, DOM, GWT, HTTP, WebSocket, and such web technologies. The app developer writes in pure Java (and maybe a tiny touch of CSS for tweaking). Vaadin transparently and auto-magically generates the HTML-CSS-JavaScript-GWT-DOM necessary to render a representation of the app’s user-interface within a web browser.
So there is no way to access the DOM from that Java server-side, nor any need to do so generally.
If you want to take control of the web technologies then Vaadin is probably not the best framework for you.
In Vaadin8 you may try this:
JavaScript.getCurrent().execute("document.getElementById('refreshButton').click()");

Info Window URL needs to be prefixed with http NOT the default https

I am using the following code in the fusion tables 'customize info window' to create hyperlinked URL's from a column in my table:
"{URL}"
This works fine in returning the clickable hyperlink in the info box except fusion maps by default tacks on https: instead of http: when the link is clicked. This causes problems when the user clicks the hyperlink and it tries to take them to a secure site when in fact it is not secure. The browsers throw up all sorts of warnings that will scare the pants off a lot of users who don't know what is happening.
Does anybody know how to remedy this and have the default be http and not the current https?
Thanks, Shep
You may want to abandon the "{URL}" approach and display the hyperlink with some simple HTML. This example from Google shows how to modify the info window's HTML in Javascript:
google.maps.event.addListener(layer, 'click', function(e) {
// Change the content of the InfoWindow
e.infoWindowHtml = e.row['Store Name'].value + "<br>";
// If the delivery == yes, add content to the window
if (e.row['delivery'].value == 'yes') {
e.infoWindowHtml += "Delivers!";
}
});
Changing the e.row['Store Name'] to your URL column name (maybe, e.row['URL']) and surrounding by a couple of hyperlink tags <a> should do the trick:
e.infoWindowHtml = "<a href='" + e.row['URL'].value + "'>Click here!</a>";
There are three ways:
Specify a full URL including protocol in your data
Use Link here in a custom info window layout
Completely override the content as in the answer above
I would recommend #1 because you can choose the right protocol for every link. However #2 is probably easier in that you can leave your data the way it is.

Insert dynamic text into Sitecore Rich Text field

I've been spending a bit of time with Sitecore recently, and I noticed the site I am working on has a copyright date in a Rich Text field. Unfortunately, it is 2012. Now, the easy way to fix this problem is to simply go in and change the Rich Text field which has the copyright information, but I don't want to have to worry about changing it in 2014.
Is there a way to insert dynamic text into the Text control? Even if I could have a sigil which I could manually replace in C# that would be preferable to either switching the Text for a Literal or force manual updates every year.
You can add your own processor to the renderField pipeline, check whether current field is RichText field and replace a token (e.g. __YEAR__) with current year:
<renderField>
<!--... other processors -->
<processor type="My.Assembly.Namespace.ReplaceTokenProcessor, My.Assembly" />
<!--... other processors -->
</renderField>
and the code of the processor:
namespace My.Assembly.Namespace
{
public class ReplaceTokenProcessor
{
public virtual void Process(RenderFieldArgs args)
{
if (args.FieldTypeKey != "rich text")
return;
args.Result.FirstPart = (args.Result.FirstPart == null) ? null : args.Result.FirstPart.Replace("__YEAR__", DateTime.Now.Year.ToString());
args.Result.LastPart = (args.Result.LastPart == null) ? null : args.Result.LastPart.Replace("__YEAR__", DateTime.Now.Year.ToString());
}
}
}
The solution Maras proposed works, but to me it sounds like a bit overkill for just one date in a RTE field.
Besides that, every RTE field that is rendered on every single page in your website is processed.
If it is only for one Year-value I would use a Literal and fill and replace the Text property of the Literal in Codebehind:
Literal.Text = FieldRenderer.Render(Context.Item, "RTE_FieldName")
.Replace("__YEAR__", DateTime.Now.Year.ToString());
Then add caching to the sublayout and it is only rendered once after the cache has been cleared.

Text URL in AIR iOS app not selectable

I'm using AIR 2.0 (soon will be updating to 3.3 with Flash CS6) to create an iPad app. We have textfields (Classic, dynamic) which sometimes contain one or multiple htmlText links which need to be clickable. In the desktop version of the program, all text is selectable and the links are easily accessed. My problem is that it takes me mashing the link like 20 times on the iPad before it will recognize that there's a link and navigate to it in Safari. The other strange thing is that none of the text appears to be selectable - I can't get the iPad cursor, copy/paste menu, etc. to show up.
I think, from reading other threads, that the hit area for the URL is only the stroke on the text itself... if that's true, what can I do to increase the hit area? Or make text selectable? It was suggested elsewhere to put movieclips behind the URLs but that's not really possible as this is all dynamic text from XML files.
I've read about StageText but I gather this is only used for input fields, which is not the case here.
I'm reasonably advanced in AS3 but I'd prefer an easy solution over re-writing large chunks of code. At the moment the only thing I can think to do is get the URL and make it so that as soon as you touch anywhere on the textfield, it navigates to the link. But this would break down if there were more than 1 URL in a given textfield.
Any ideas?
I had this exact same issue, and it's had me flummoxed for a while.
Here's what I did to get the desired behaviour:
1) Instead of using a listener for TextEvent.LINK, listen for MouseEvent.CLICK (or TouchEvent.TAP) on the TextField.
eg.
var tf:TextField = new TextField();
tf.addEventListener(MouseEvent.CLICK, linkClicked);
2) In the linkClicked() handler, you use getCharIndexAtPoint() to determine the index of the character that was clicked, and then from that determine the URL from the TextFormat of the character. This is adapted from a post by Colin Holgate on the Adobe Forums (http://forums.adobe.com/thread/231754)
public function linkClicked(e:MouseEvent):void {
var idx:int = e.target.getCharIndexAtPoint(e.localX, e.localY);
trace("Tapped:",idx);
var tf:TextFormat = e.target.getTextFormat(idx);
if(tf.url != "" && tf.url != null) {
var linkURL:String = tf.url;
trace(linkURL);
// Hyperlink processing code here
dispatchEvent(new UIEvent(UIEvent.LINK_TAPPED,tf.url));
}
}
3) The last line (dispatchEvent()) is sending a custom event to another function to process the link, but you could easily inline your code here.
I've tested on an iPad 3 running iOS6.1, building with AIR3.5. Links are much more responsive, and I don't find myself mashing the screen trying to hit the stroke of the text!

ASP.net MVC - IE9 has an extra item with an empty key in forms collection

I have a bit of an odd problem, and I'm struggling to track down the root cause...
I have an ASP.net MVC site, and recently one of my colleagues started using IE9, and noticed a problem with one of the pages - it wasn't updating on click of save.
I figured that this would probably be a script issue, as there is a fair bit of jQuery used on this page, and it may still be, but:
If I submit this page in Chrome (or in IE8/7/6), then I get a forms collection with 11 items in it, as I would expect. If I submit the same page in IE9, I get an extra item at the end of the collection which has an empty string as key and an empty string as the value. This causes the call to UpdateModel() to not work (but not throw an exception) - none of these values are updated in my object, and the ModelState is still showing as valid.
So far, I've only found this one page, but I'm curious if anybody might know what is causing this?
Update 04/04/2011 - Narrowed down the culprit:
I removed bits of code until this worked and narrowed it down to some code in my validation. I use the jQuery validate plugin, and had the following as a submit handler (some redaction performed on names...):
submitHandler: function (form) {
var submitForm = true;
var newValue, originalValue;
newValue= $("#newValue").val();
originalValue= $("#originalValue").val();
if (newValue!= originalValue) {
//affectedValues is an array populated at the top of the page.
if ($.inArray(originalValue, affectedValues) != -1 &&
$.inArray(newValue, affectedValues) == -1) {
submitForm = confirm("Are you sure you want to do this");
}
}
if (submitForm) {
form.submit();
}
},
Removing this from the code (which I can thankfully do, as it's a bit of legacy code), seems to make this work, my empty item in the forms collection is gone. If anybody has any idea why this might have been happening, that'd be great.
Might be worth checking all the form fields in firebug to see if you have any un-named elements? I know I got caught out by the Select behaviour in IE before.
pdate 04/04/2011 - Narrowed down the culprit:
I removed bits of code until this worked and narrowed it down to some code in my validation. I use the jQuery validate plugin, and had the following as a submit handler (some redaction performed on names...):
submitHandler: function (form) {
var submitForm = true;
var newValue, originalValue;
newValue= $("#newValue").val();
originalValue= $("#originalValue").val();
if (newValue!= originalValue) {
//affectedValues is an array populated at the top of the page.
if ($.inArray(originalValue, affectedValues) != -1 &&
$.inArray(newValue, affectedValues) == -1) {
submitForm = confirm("Are you sure you want to do this");
}
}
if (submitForm) { form.submit(); }},
Removing this from the code (which I can thankfully do, as it's a bit of legacy code), seems to make this work, my empty item in the forms collection is gone. If anybody has any idea why this might have been happening, that'd be great.
I had some problems with my MVC sites due to the caching features introduced for IE9. My work around was to disable caching in my controller by adding an attribute:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public class FaxController : Controller
FF, Chrome, Opera sends just value of FORM elements (button, input,..) with NAME.
IE always sends elements to server, even Submit with empty name and value which causes error.
So to be sure, always name elements.

Resources