Bootstrap4XPages plugin: how to catch a change event with Select2 Picker? - twitter-bootstrap-3

I am using the BS4XSP plugin and the Select2 Picker/Combo for a Listbox. Unfortunately when using it I am not able to catch the change/click/keyup event of that Listbox to execute code. This is my code extract:
<xp:div rendererType="bootstrap.Panel" title="Facets" id="facets">
<p>
<xp:listBox id="searchFacets" multiple="true" value="#{sessionScope.searchFacets}">
<xp:selectItems>
<xp:this.value>
<![CDATA[#{javascript:search.getFacets()}]]>
</xp:this.value>
</xp:selectItems>
</xp:listBox>
<bx:select2PickerCombo id="select2PickerCombo1" for="searchFacets" formatSelection="#{javascript:search.init()}">
</bx:select2PickerCombo>
</p>
<xp:button value="Update" id="button2" styleClass="btn-sm btn-primary">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="result">
<xp:this.action>
<![CDATA[#{javascript:search.init();}]]>
</xp:this.action>
<xp:this.onComplete>
<![CDATA[XSP.partialRefreshGet("#{id:facets}");]]>
</xp:this.onComplete>
</xp:eventHandler>
</xp:button>
</xp:div>
Any ideas how to trigger my code that is currently in the button below the listbox directly through the Listbox / Select2 picker?

I don't think it can be done when using the bx:select2PickerCombo control. The only way I can think of to do this would be to manually invoke the select2 plugin.
Note that I'm still loading the select2 library from the Bootstrap4XPages plugin, but in this scenario you can also just add it directly to your application, no need to only use the Bootstrap4XPages plugin for that.
<xp:this.resources>
<xp:script
src="/.ibmxspres/.extlib/bootstrap/select2/select2.min.js"
clientSide="true">
</xp:script>
<xp:styleSheet
href="/.ibmxspres/.extlib/bootstrap/select2/select2.css"></xp:styleSheet>
<xp:styleSheet
href="/.ibmxspres/.extlib/bootstrap/select2/select2-bootstrap.css"></xp:styleSheet>
</xp:this.resources>
<xp:div
title="Facets"
id="facets">
<xp:text
escape="true"
id="computedField2"
value="#{javascript:(new Date()).getTime()}">
</xp:text>
<p>
<xp:listBox
id="searchFacets"
multiple="true"
value="#{sessionScope.searchFacets}">
<xp:selectItems>
<xp:this.value>
<![CDATA[#{javascript:['option 1', 'option 2']}]]>
</xp:this.value>
</xp:selectItems>
</xp:listBox>
</p>
<xp:scriptBlock
id="scriptBlock1">
<xp:this.value><![CDATA[
x$("#{id:searchFacets}").select2().on('change', function() {
console.log('value of select2 has changed...');
//call the event handler on the server, refresh a different target when it's done
$('[name="$$xspsubmitid"]').val('#{id:myEventHandler}');
XSP._partialRefresh("post", $("form")[0], '#{id:result}', {
onComplete : function() {
console.log('calling function in onComplete event');
XSP.partialRefreshGet("#{id:facets}");
}
});
});
]]></xp:this.value>
</xp:scriptBlock>
</xp:div>
<!--this is the event handler that gets called when the value changes -->
<xp:eventHandler
event="onclick"
id="myEventHandler"
submit="true"
refreshMode="none">
<xp:this.action>
<![CDATA[#{javascript:print('call init function here' + getComponent('searchFacets').getValue() );}]]>
</xp:this.action>
<xp:this.onComplete>
<![CDATA[XSP.partialRefreshGet("#{id:facets}");]]>
</xp:this.onComplete>
</xp:eventHandler>
<xp:div
id="result">
<xp:text
escape="true"
id="computedField1"
value="#{javascript:(new Date()).getTime()}">
</xp:text>
</xp:div>

Related

Richtext custom buttons do not load initially when using content control

I have a rich text field inside a dynamic content control from exension library. In the rich text field I have set a few attributes to show specific buttons.
My problem is that the initial load of the rich text field does not display the custom buttons, I need to click the link to load the buttons. It does not seem to matter if the key is in the url or not, same results.
How can I make sure the attributes buttons are loaded initially?
Here is the code for you to try for your self, paste it in to a new xpage
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom">
<div style="width:300px;padding:20px">
<xp:link escape="true" text="Load Content"
id="link2">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[XSP.showContent("#{id:dynC}","key1")]]></xp:this.script>
</xp:eventHandler>
</xp:link>
<br /><br />
<xe:dynamicContent id="dynC" useHash="true">
<xp:this.facets>
<xp:panel xp:key="key1">
<xp:this.data>
<xp:dominoDocument var="d" formName="Doc"></xp:dominoDocument>
</xp:this.data>
<xp:inputRichText id="inputRichText1"
value="#{d.Body}">
<xp:this.dojoAttributes>
<xp:dojoAttribute name="toolbar">
<xp:this.value>
<![CDATA[#{javascript:"[['FontSize'],['Bold','Italic','Underline','Strike'],['TextColor','BGColor']," +
"['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','NumberedList','BulletedList']," +
"['Outdent','Indent']," +
"['RemoveFormat','-','MenuPaste','-','Undo','Redo','-', 'Image','Table','Link'],['Source']]"}]]>
</xp:this.value>
</xp:dojoAttribute>
</xp:this.dojoAttributes>
</xp:inputRichText>
</xp:panel>
</xp:this.facets>
</xe:dynamicContent>
</div>
</xp:view>
This is what it looks like after initial load
This is what it looks like after clicking the link

Xpages: How to toggle searchClear glypicon from search field

My Xpage has a Bootstrap style search field. When the user types something in the search field I want the clear glypicon to appear, allowing the user to clear the search field and reset the view.
I found some code to do this but am unable to integrate it into my Xpages app. When I try to run this and enter text into the field, Chrome throws the error:
Uncaught TypeError: Cannot read property
'toLowerCase' of undefined
My code is below:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:styleSheet href="/cc_CommonSearchBar.css"></xp:styleSheet>
</xp:this.resources>
<xp:div style="width:300px" styleClass="btn-group">
<xp:div styleClass="input-group add-on">
<xp:inputText styleClass="input-medium search-query"
id="searchinput" type="text">
<xp:this.attrs>
<xp:attr name="placeholder" value="Search"></xp:attr>
</xp:this.attrs>
<xp:eventHandler event="onkeyup" submit="false">
<xp:this.script><![CDATA[var srcClr = XSP.getElementById("#{id:searchclear}");
srcClr.toggle(Boolean($(this).val()));
$(".searchclear").toggle(Boolean($(".searchinput").val()));
$(".searchclear").click(function(){
$(this).parent().find('.searchinput').val('').focus();
$(this).hide();
});]]></xp:this.script>
</xp:eventHandler></xp:inputText>
<xp:span id="searchclear"
styleClass="searchclear glyphicon glyphicon-remove-circle">
</xp:span>
<xp:div styleClass="input-group-btn">
<xp:button styleClass="btn btn-default" type="submit"
style="height:34px">
<i class="glyphicon glyphicon-search" />
</xp:button>
</xp:div>
</xp:div>
</xp:div>
</xp:view>
With Frank's answer below I was able to get this to almost work. My only problem now is a bootstrap issue; the reset x appears over the search button. But I almost have it:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:styleSheet href="/cc_CommonSearchBar.css" />
</xp:this.resources>
<div class="input-group" style="width:300px">
<!-- <div class="btn-group">-->
<input id="searchinput" type="text" class="form-control"
placeholder="Search for..." />
<span id="searchclear" class="glyphicon glyphicon-remove-circle" />
<span class="input-group-addon" id="basic-addon2">
<i class="glyphicon glyphicon-search" />
</span>
</div>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[$(document).ready(function(){
$("#searchinput").keyup(function(){
$("#searchclear").toggle(Boolean(this.value));
});
$("#searchclear").toggle(Boolean($("#searchinput").val()));
$("#searchclear").click(function(){
$("#searchinput").val("").focus();
$("#searchclear").hide();
});
});]]></xp:this.value>
</xp:scriptBlock>
</xp:view>
first you need to identify where exactly it is going wrong.
You are calling $(".searchinput").val(), but in your code there is no element with a class 'searchinput'.
Either add 'searchinput' class to the search box.
<xp:inputText styleClass="searchinput input-medium search-query"
id="searchinput" type="text">
</xp:inputText>

How do I display two div on button click using toggle?

I am developing application in MVC. I have placed one button. I displayed the div while clicking a button. On clicking a button I used toggle to show the div. Now my problem is inside the div I need to display another form or div. Is it possible?
My code is
if (button_id == "reminder_button") {
$('.reminder').toggle("slow")
{
$('#remdr').appendTo('reminder');
};
View code:
<div class="remdr" id="remdr" style="display:none">
#using (Html.BeginForm("Reminder", "Appt", FormMethod.Post, new { id = "rem" }))
{
#Html.Label("Reminder Text")
<input type="text" name="Remtitle" style="width:200px" />
#Html.Label("Notifications")
#Html.DropDownList("Reminderlist", new SelectList(listItems, "Value", "Text"))
<input type="text" name="number" style="width:200px" />
#Html.DropDownList("Reminder", new SelectList(list, "Value", "Text"))
<input type="submit" name="reminder" value="Remind me">
<div id="Addnotification" style="color:blue; font-size:15px">Add Notification</div>
}
</div>

Dojo Dijit Claro Theme disable mouse over

I´ve been trying to change the Dojo Claro theme because it´s too light and i wanted to get rid of some of the efects.
One of them is the mouse over of form dijits.
Is there any way to disable, in general, the effect of the mouse over in Buttons and inputs like textboxes, filtering selects etc.....
I cannot catch the css on firebug when the mouse is 'overing' that elements. There should be a class that it´s appended to the element that produces that effect.
can anyone tell what it is?
Thanks
Taken from the Simple-Enabled-Button on the Basic Form Widgets tab of the theme tester - http://download.dojotoolkit.org/release-1.7.0/dojo-release-1.7.0/dijit/themes/themeTester.html?theme=claro.
No hover:
<span class="dijit dijitReset dijitInline dijitButton" role="presentation" widgetid="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitButtonNode" data-dojo-attach-event="ondijitclick:_onClick" role="presentation">
<span class="dijitReset dijitStretch dijitButtonContents" data-dojo-attach-point="titleNode,focusNode" role="button" aria-labelledby="dijit_form_Button_1_label" tabindex="0" id="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitIcon dijitIconTask" data-dojo-attach-point="iconNode"></span>
<span class="dijitReset dijitToggleButtonIconChar">?</span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_1_label" data-dojo-attach-point="containerNode">Simple</span>
</span>
</span>
<input type="button" value="" class="dijitOffScreen" tabindex="-1" role="presentation" data-dojo-attach-point="valueNode">
</span>
Hover:
<span class="dijit dijitReset dijitInline dijitButton dijitButtonHover dijitHover" role="presentation" widgetid="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitButtonNode" data-dojo-attach-event="ondijitclick:_onClick" role="presentation">
<span class="dijitReset dijitStretch dijitButtonContents" data-dojo-attach-point="titleNode,focusNode" role="button" aria-labelledby="dijit_form_Button_1_label" tabindex="0" id="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitIcon dijitIconTask" data-dojo-attach-point="iconNode"></span>
<span class="dijitReset dijitToggleButtonIconChar">?</span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_1_label" data-dojo-attach-point="containerNode">Simple</span>
</span>
</span>
<input type="button" value="" class="dijitOffScreen" tabindex="-1" role="presentation" data-dojo-attach-point="valueNode">
</span>
Identical apart from the outer span's classes ...
No hover:
dijit dijitReset dijitInline dijitButton
Hover:
dijit dijitReset dijitInline dijitButton dijitButtonHover dijitHover
The other form fields may differ, but you'll have to take a look at those. From what little I've looked, I think each form dijit has its own hover class(es).
dijitHover appears to be a functional class, rather than a UI class, as I can't find it in the Dojo 1.8.3 css or JS:
d:\dev\js\dojo-release-1.8.3>findstr /i/s "dijithover" *.css
FINDSTR: // ignored
d:\dev\js\dojo-release-1.8.3>findstr /i/s "dijithover" *.js
FINDSTR: // ignored
but I can find dijitButtonHover:
d:\dev\js\dojo-release-1.8.3>findstr /i/s "dijitbuttonhover" *.css
FINDSTR: // ignored
dijit\themes\claro\claro.css:.claro .dijitButtonHover .dijitButtonNode,
dijit\themes\claro\claro.css:.dj_ie .claro .dijitToolbar .dijitButtonHover .dijitButtonNode,
dijit\themes\claro\claro.css:.claro .dijitToolbar .dijitButtonHover .dijitButtonNode,
dijit\themes\claro\form\Button.css:.claro .dijitButtonHover .dijitButtonNode,
dijit\themes\claro\Toolbar.css:.dj_ie .claro .dijitToolbar .dijitButtonHover .dijitButtonNode,
dijit\themes\claro\Toolbar.css:.claro .dijitToolbar .dijitButtonHover .dijitButtonNode,
dijit\themes\nihilo\form\Button.css:.nihilo .dijitButtonHover .dijitButtonNode,
dijit\themes\nihilo\nihilo.css:.nihilo .dijitButtonHover .dijitButtonNode,
dijit\themes\nihilo\nihilo.css:.nihilo .dijitToolbar .dijitButtonHover,
dijit\themes\nihilo\Toolbar.css:.nihilo .dijitToolbar .dijitButtonHover,
dijit\themes\soria\form\Button.css:.soria .dijitButtonHover .dijitButtonNode,
dijit\themes\soria\soria.css:.soria .dijitButtonHover .dijitButtonNode,
dijit\themes\soria\soria.css:.soria .dijitToolbar .dijitButtonHover,
dijit\themes\soria\Toolbar.css:.soria .dijitToolbar .dijitButtonHover,
dijit\themes\tundra\form\Button.css:.tundra .dijitButtonHover .dijitButtonNode,
dijit\themes\tundra\Toolbar.css:.tundra .dijitToolbar .dijitButtonHover,
dijit\themes\tundra\tundra.css:.tundra .dijitButtonHover .dijitButtonNode,
dijit\themes\tundra\tundra.css:.tundra .dijitToolbar .dijitButtonHover,
dojox\grid\enhanced\resources\claro\EnhancedGrid.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\claro\EnhancedGrid.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\claro\EnhancedGrid.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\grid\enhanced\resources\claro\EnhancedGrid.css:.claro .dojoxGridFBarInfoTD .dojoxGridFBarClearFilterBtn.dijitButtonHover .dijitButtonText {
dojox\grid\enhanced\resources\claro\Filter.css:.claro .dojoxGridFBarInfoTD .dojoxGridFBarClearFilterBtn.dijitButtonHover .dijitButtonText {
dojox\grid\enhanced\resources\claroEnhancedGrid.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\claroEnhancedGrid.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\claroEnhancedGrid.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\grid\enhanced\resources\claroEnhancedGrid.css:.claro .dojoxGridFBarInfoTD .dojoxGridFBarClearFilterBtn.dijitButtonHover .dijitButtonText {
dojox\grid\enhanced\resources\EnhancedGrid.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\EnhancedGrid.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\EnhancedGrid.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\grid\enhanced\resources\Filter.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\Filter.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\Filter.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\grid\enhanced\resources\tundra\EnhancedGrid.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\tundra\EnhancedGrid.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\tundra\EnhancedGrid.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\grid\enhanced\resources\tundraEnhancedGrid.css:.dijitButtonHover .dojoxGridFBarCloseBtnIcon {
dojox\grid\enhanced\resources\tundraEnhancedGrid.css:.dijitButtonHover .dojoxGridFCBoxRemoveCBoxBtnIcon {
dojox\grid\enhanced\resources\tundraEnhancedGrid.css:.dijitButtonHover .dojoxGridFStatusTipDelRuleBtnIcon {
dojox\layout\resources\RotatorContainer.css:.rotatorIcons .dijitButtonHover .previous{background-position:0 -16px;}
dojox\layout\resources\RotatorContainer.css:.rotatorIcons .dijitButtonHover .next{background-position:-16px -16px;}
Dojo buttons have 3 hierarchical layers of Html SPAN nodes.
Whenever the mouse enters the button, only the top SPAN is changed. Two CSS classes are appended: "dijitButtonHover" and "dijitHover" (as you show in your "No hover" and "hover" HTML markup).
To change the Dojo Claro to your own design when the mouse enters the button, try the CSS selector:
.claro .dijitReset.dijitInline.dijitButton.dijitButtonHover{}
This may not work if you have in your CSS stylesheet other selectors with a higher specific weight. If this is the case, add some of your CSS classes to the above selector, in order to increase its weight.

How to add buttons to dojo titlepane

Is there any way to add buttons to TitlePane header(right side of title bar), so that i can do some operations(download,delete...)
Thanks in advance.
dijit TitlePane header contains the following
<div class="dijitTitlePaneTitleFocus" data-dojo-attach-point="focusNode" aria-pressed="true" role="button" aria-controls="dijit_TitlePane_0_pane" tabindex="0">
<span data-dojo-attach-point="arrowNode" class="dijitInline dijitArrowNode" role="presentation"></span><span data-dojo-attach-point="arrowNodeInner" class="dijitArrowNodeInner">-</span><span data-dojo-attach-point="titleNode" class="dijitTitlePaneTextNode" style="user-select: none;">Rule</span>
<span class="dijit dijitReset dijitInline dijitButton" role="presentation" widgetid="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitButtonNode" data-dojo-attach-event="ondijitclick:__onClick" role="presentation">
<span class="dijitReset dijitStretch dijitButtonContents" data-dojo-attach-point="titleNode,focusNode" role="button" aria-labelledby="dijit_form_Button_1_label" tabindex="0" id="dijit_form_Button_1" style="user-select: none;">
<span class="dijitReset dijitInline dijitIcon dijitNoIcon" data-dojo-attach-point="iconNode"></span><span class="dijitReset dijitToggleButtonIconChar"></span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_1_label" data-dojo-attach-point="containerNode">x</span></span></span></span>
</div>
As you see there are several attach points we can reference.
To add any item, even a dijit or custom widget do the following to place items after the last in the focusNode attach point (note: you have to style it correctly in order for items to appear in the position you want)
var myTitlePane = new TitlePane({ title: "TitlePane" });
var deleteButton = new Button({
label: 'x',
onClick: function () {
//do something here like delete the titlepane
//alert();
}
});
deleteButton.placeAt(rulesTitlePane.focusNode);
This will produce something that looks like this,
Or you can replace everything and create whatever you want in the focusNode.
There is. I was able to do it using the .placeAt() method in the added dijit's creation, such as below:
In index.htm
<div id="divMap"></div>
In main.js within callback
ready (function() {
var ttpMyTitlePane = new TitlePane({
title: 'My Title'
});
divMenu.appendChild(ttpMyTitlePane.domNode);
var btnMyButton = new Button({
label: 'ButtonText',
onClick: function() {
// do stuff
}
}).placeAt(ttpMyTitlePane.domNode);
}