Does the Office.js API support multiple range selection? - ms-word

I need to select multiple ranges simultaneously via the Office.js API like you can do in the MSWord UI by holding down the CTRL key and highlight multiple non-contiguous paragraphs, like the screenshot below:
This attempt doesn't work. Rather than highlighting the first two instances of the word "the" in the document, it's highlighting the first, then highlight the second afterwards:
Word.run(function (context) {
// Set up the search options.
var options = Word.SearchOptions.newObject(context);
options.matchCase = false;
options.ignoreSpace = true;
options.ignorePunct = true;
options.matchWildcards = true;
var searchText = "the";
var searchResults = context.document.body.search(searchText, options);
context.load(searchResults);
return context.sync().then(function () {
searchResults.items[0].select();
searchResults.items[1].select();
});
});

No, none of the APIs support multiple selections. Even the ability for the user to do so, using Ctrl+select is relatively new. The capability was never carried over to the APIs.
The closest the APIs can do is to highlight (or otherwise format) the Range objects of interest. There is such functionality in Word's dialog box which is also available to the COM APIs, but I don't find an equivalent for the JS APIs...

To confirm what Cindy mentioned, Non-continuous selections are not only not supported in Office.js (for Word, we DO support them for Excel though) but also not supported manually on other platforms (i.e. Word Online).

It might be possible.
I ran across an odd result when using bindings and Office.context.document.goToByIdAsync(). Using this function you can navigate to any binding without having to call Word.Run(), which is nice. There is an option called SelectionMode, which by default does not select the binding, but can be set to select the contents of the binding. Weirdly, selecting the content in this way does not deselect the current selection! Which is not the result I wanted, fwiw; to me it is a nuisance that requires me to "deselect" any current selection before I use goToByIdAsync. But it's possible you could use this to select multiple ranges by wrapping them in contentControls and then creating bindings on them, then calling goToByIdAsync (with SelectionMode set to Select) on each binding. I have not tested this.
Edit
Actually, the previous selection is deselected, but it remains highlighted as though it is still selected. This appears to be a display bug.

Related

Can I get the style object and Get the property of it?

I wanted to use javascript addin's to get the style object and get some proerties of it for example maybe paragraph property and get the indentation of this specific style but I cant get to the style object and get the property of it. I know that there is a collection of every style in document but I cant get any properties of those. There is way to change style in selected range but it could be very fine if I could get style from the range maybe and like i said erlier get some properties of it.
This is code in Word VBA that is example of property i want to see value of:
documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
We can set the value to any variable:
Dim var As Integer/Long
Let var = documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
As far as I know the office.js API for Word does not currently (v. 1.4) provide any Style objects with the kind of properties that you are used to seeing via the Object Model that VBA uses. All it lets you do is get the style names (localized and built-in) associated with another object such as a range, a paragraph, or various style properties associated with a table.
i.e. at the moment, the only way you would be able to get detailed style information would probably be to retrieve the document's XML and interpret that. Hard, I suspect.
I think that probably answers your question but in case you were looking for code to retrieve a style, to get the style name of a range, say, is straightforward, e.g. in Script Lab you can start with one of the basic JavaScript samples and modify its run function so it looks like this:
function run() {
return Word.run(function(context) {
var range = context.document.getSelection();
range.load("style");
return context.sync().then(function() {
console.log('The selected style was "' + range.style + '".');
});
});
}
Precisely which style name you get depends on the range - if you select two paragraphs with different styles, the style name will be "", and so on.

SAPUI5 - How do I disable text input in DateRangeSelection

I need to completely disable text entry on a DateRangeSelection, so that only the calendar selection can be accepted..
I can the disable text input for a DatePicker component with...
view.byId("__reportDate")._bMobile = true;
Unfortunately this doesn't work for a DateRangeSelection.
Is there anything else I can try?
There does not seem to be a standard property to do it, you can however tweak the underlying input element used to set it to readonly. This would disable any text input in the field. This might be one of the ways to do it.
var oDateSel = this.getView().byId("dateSel");
$("#"+oDateSel.sId+" input").prop("readonly",true);
Note: This is certainly not a standard approach according to the UI5 standards. Also you might have to set a handler to set the element to readonly if the control is re-rendered.
Solution was...
var dateSel = sap.ui.getCore().byId("dateRange");
$("#"+dateSel.sId+" input").prop("disabled",true);
(readonly wiped out the placeholder in IE).

Is there a way to avoid holding the ALT key when cycling through input fields within a SAPUI5 table?

I have a SAPUI5 table which contains input fields. I have prepared an example at http://jsfiddle.net/bgerth/x8h92mz8/.
When you press ALT+TAB you can cycle through the input fields within the table (I only found that out by looking at sap.m.ListBase.prototype._startItemNavigation).
Only pressing TAB focuses the first element outside the table.
I consider that rather non-intuitive. Is there a way to make TAB alone work the same way?
Update:
Alt+Tab works in Chrome and Safari, but not Firefox (45.0.2) on my Mac. It doesn't work at all on Windows, as that combination is reserved to toggle through open application windows.
There are two solutions I discovered so far to address this problem
Proposal 1: Adapt tab key handling
I have found the blog SAPUI5 Table Navigation with Tab Key by Klaus Kronawetter which adds extra keyboard handling to a sap.ui.table.Table. I adapted his code for a sap.m.Table which you can find at http://jsfiddle.net/bgerth/os6r096y.
Unfortunately, the code is rather lenghty.
Proposal 2: Enable up/down arrow keys
After further investigation, I decided that the solution from proposal 1 above is too much hassle.
Instead, I adapted the class sap.ui.core.delegate.ItemNavigationmentioned above, which is internally employed by sap.m.ListBase. In essence, you can cycle through the input fields with up and down arrow keys.
I have prepared an example at http://jsfiddle.net/bgerth/0r9L30wd. The relevant code is
var fnPatchedItemNavigationsetItemDomRefs = sap.ui.core.delegate.ItemNavigation.prototype.setItemDomRefs;
sap.ui.core.delegate.ItemNavigation.prototype.setItemDomRefs = function setItemDomRefsPatched(aItemDomRefs) {
// 'this' is now the instance of sap.ui.core.delegate.ItemNavigation
jQuery.sap.log.debug("Patched version of sap.ui.core.delegate.ItemNavigation.setItemDomRefs");
var aInputFields = $(aItemDomRefs).find("input:enabled").get();
if (aInputFields[0]) {
// There is at least one enabled input field in this table
return fnPatchedItemNavigationsetItemDomRefs.call(this, aInputFields);
} else {
return fnPatchedItemNavigationsetItemDomRefs.call(this, aItemDomRefs);
}
}

GTM Reduce number of tags

GTM up and running, main UA tag in place along with a ClickListener tag.
To reduce the number of macros, i use dataLayer variable Macros for event category, action, label, value & interaction, so they can be used for many rules and tags.
So i want to collect data from one link/button (Add to Fav), i add a rule to listen for the click using {{event}} equals gtm.click and {{Event Label}} equals Add_to_Fav (the label i push to the DL via onclick.
All good so far, but i need to create another UA tag (Track Type - event) that fires on the rule made previously. And this is my question, using this method seems to create many tags. If i have another 20 links that i want to collect data from, do i need to keep creating tags like this. Surely, this will affect page load speed with many tags firing on all pages.
Hope thats all clear.
If you need to retrieve the link text to use it as an event label you do not need many many event tracking tags, that would be horribly verbose. Instead you can use a custom javascript macro - the cool thing about them being that you can use existing macros inside your custom function.
If you create a click listener or link click listener this will create a few macros - one of them is {{element}}, which is the DOM element that received a click.
Now you create a macro of the type "custom java script", which must contain an anonymous function with a return value.
The barebones version of a function that retrieves the text of a clicked link would be
function() {
var el = {{element}};
return el.innerText;
}
(actually you do not need the variable assigment, you could use {{element}}.innerText directly).
You name the macro e.g. Linktext and use the macro {{Linktext}} in your single event tracking tag where it will dynamically be set to the value of the text of the clicked link (although you might want to check cross browser support for innerText, or maybe use innerHTML instead which serves in you use case probably the same purpose).

Alter input of form before it is submitted

I'm creating a multilingual Drupal site and trying to implement a search function, that only displays results in the current language, that the user is viewing the site through.
Using Drupals own searchfunction at /search/node it is possible to select which language to search for through the "Advanced search" options, and it works perfectly. However, I dont want to expose these language selectboxes, I just want it to only search in the current language automatically.
What's the best option to do this?
I have one solution where I create a hook_form_alter function, that sets the #default_value in the language selectboxes to the current language, and then I hide the whole "advanced options" with in css. This doesnt seem very right though.
I think the most clean solution would be to hook into Drupals form-processing process and append ex "language:en" to the input text, but I cannot get this to work.
Does anyone know if it is possible via one of the Drupal form related alter functions, to get a hold of the input text and alter it before drupal does its final processing of it?
To answer your question specifically, while using 'hook_form_alter', you have a referenced variable called '$form_state'. This stores the values in the form, and any change there will be passed further.
Also,
I think setting a default value and hiding the field is a good solution as any, only, if you are hiding it you should do it server side, while altering the form. The same field you are setting the default value to. like this:
$fieldname['#type'] = 'hidden'.