Is there a way to change the text of checked/unchecked MCheckBox states? - mgwt

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?

Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.

Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171

Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

Related

Sorting a Listbox in C++

first time asking questions here. I'm having trouble sorting a listbox in a c++ form. I would much rather do this in C# but it's a class requirement unfortunately. Here's the code in question:
void updateCourseDisplay()
{
courseListBox->Items->Clear();
set<Course*> courseSet = courseControl->getCourseSet();
std::set<Course *>::iterator it;
for (it = courseSet.begin(); it != courseSet.end(); ++it)
{
Course * c = (*it);
String ^courseId = gcnew String((c->getID().c_str()));
String ^courseName = gcnew String((c->getName().c_str()));
courseListBox->Items->Add(courseId + " - " + courseName);
}
courseListBox->System::Windows::Forms::ListBox::Sort();
populateCopyStudentsComboBox();
}
I know this is pretty messy but I didn't want to mess around with creating managed objects to add to the form. The error I'm getting when I try and run this says that System::Windows::Forms::ListBox::Sort() would have been called but it is inaccessible. All I want is simple ordering of the list by the string value. Any thoughts?
Sort is a protected method that can not be accessed from the "outside". You should set the public Sorted property to true instead.

How to override the textbox content in CSWPFAutoCompleteTextBox

I am using the autocomplete textbox from this MSDN link.
Question:
CSWPFAutoCompleteTextBox has property "AutoSuggestionList" which I bound this to observable string collection. Each string is made of id + description. When user selects an item from dropdown, how can I override the texbox content? I want to manipulate the text box content.
This is a textbox that extends a wpf combobox to make it searchable.
When the user types in a string in the textbox, it displays matching strings as a dropdown, user selects an item and the item is displayed in the textbox.
the question is how to override the textbox contents of this control.
Without actual format of your code it is hard to answer precisely, but for example, if your strings are
string[] suggestions = {"0: Yes", "1: No", "666: whatever"}
Then you could get the number by something like
sugestedString.Substring(0, sugestedString.IndexOf(':'));
EDIT: I misunderstood the question. So if I now understands correctly, you might do it with
for(int i = 0; i < suggestions.Length; i++) {
if(suggestions[i] == selectedString) {
return i;
}
}
If you seek only a number within your list of all possible suggestions.
If you seek a number within narrowed-down suggestions, it gets somewhat more difficult.
You firstly need to note down what user has typed so-far (e.g. "Aut"). Then you need what he actually selected (e.g. "Automotive"). With those things, you can then search all your possible suggestions, count how many of them satisfies the user-typed beginning and finaly which of them is the selected one. It might look like this:
int counter=0;
for(int i = 0; i < suggestions.Length; i++) {
if( suggestions[i].StartsWith(typedString)) {
counter++;
if(suggestions[i] == selectedString) {
counter;
}
}
}

How to find out if an XPages view(Panel) is sorted by a viewColumnHeader sort toggle switch?

I'm displaying a view using a viewPanel. The view contains some columns which are enabled to be sorted in both directions, which is working fine.
Now I'd need to find out if the view has been resorted by the user by being clicked on the "Sort Toggle" in the viewColumnHeader.
Is there a property or a method which I can access programmatically to find this out?
Or is there an event in the viewPanel I could intercept or listen to?
Update:
I found that the class UIViewColumnHeader (which is extended by XspViewColumnHeader) has some static properties describing the icons (see here) - could I check for them? And if yes, how?
The sort column should be defined on the dominoView datasource in the sortColumn property, whose Java class is com.ibm.xsp.model.domino.DominoViewData. That can be accessed by calling getData() on the ViewPanel
So you should be able to use getComponent("myViewPanel").getData().getSortColumn() in SSJS. By default I suspect it will be blank.
Ok, with the help of those both sites, I solved resp. worked around my problem:
First, there was Naveen's solution how to Getting ViewPanel Headers programmatically
Second, Mark Leusink's article about the order of events in XPages.
This led me to following code:
<xp:this.beforeRenderResponse><![CDATA[#{javascript:
var viewPnl:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1");
var list:java.util.List = viewPnl.getChildren();
var replaceRespCol = false;
for (var i = 0 ; i < list.size(); i++) {
var viewCol:com.ibm.xsp.component.xp.XspViewColumn = list.get(i);
var viewHdr:com.ibm.xsp.component.xp.XspViewColumnHeader = viewCol.getHeader();
if (#RightBack(viewHdr.getSortIcon(), "/") != "sort_none.gif") {
replaceRespCol = true;
}
}
if (getSearchKey() != "") {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else if (replaceRespCol == true) {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else {
getComponent("viewColumn1").setRendered(true);
getComponent("viewColumn1b").setRendered(false);
}}]]></xp:this.beforeRenderResponse>
which enables me now to dynamically show a categorized column (viewColumn1)
- if no filter/search key is entered and
- no re-sort via the headers is done.
Otherwise, a flat column (viewColumn1b) is shown. HTH

text field attributes/methods dynamics crm 2011

I'm looking a method or way how to check that the text field in crm form is "null"
I've got a tab, there are section and text field inside of it;
furthermore, I'm using that function in order to hide/show tab.
function setVisibleTabSection(tabname, TextFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (TextFieldName == null)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (section != null) {
show == true;
tab.setVisible(show);
}
}
}
}
however, It doesn't work. There is nothing inside of the text box, and the tab expanded anyway.
by the way, parameters, which I give the function: "tab_8", "new_conf_report", false
where the secon one the name of the text field
Try
if (section != null && section !="")...
You may find that a field which is initially blank is null, whereas one from which you have deleted content but not yet saved the form is simply an empty string.
Certainly worth a shot.
show==true
is incorrect as others have pointed out (needs to be show=true) but is simply redundant as written inside the same IF statement, just replace next line as:
tab.setVisible(true);
It is possible you intended "show" to be the default tab state to use if text field is not empty, in which case just move this line outside the IF instead of changing it (as shown below)
It looks like the construction using the third "show" parameter is to allow you to use the function to set the tab state to a specific state of shown or not without looking for a text field value at all. You would need to pass parameters as eg tabname,,true - you might consider swapping the TextFieldName and Show parameters so it is easier to just drop the third rather than remember to double-comma.
While we're fixing stuff, lets replace that variable "section" with something with a more meaningful name:
function setVisibleTabSection(tabname, show, TextFieldName) //usage: show is state Tab will have if no TextFieldName is specified, or if text field is empty
{
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null)
{
if (show==null){show=true;}
if (TextFieldName == null)
{
tab.setVisible(show);
}
else
{
var strFieldValue = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (strFieldValue != null && strFieldValue !="")
{show=true;}
tab.setVisible(show);
}
}
}
I don't see anything wrong with your Javascript (besides what Guido points out, which basically will only set the tab to visible if you pass in true for show). Use the debugging tool within IE by pushing F12, and set a break point at the top of your function to see where your logic is failing.
If you've never debugged javascript before, see http://social.technet.microsoft.com/wiki/contents/articles/3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx
or
How to debug jScript for Dynamics CRM?
I think there is a typo in the code:
show == true;
actually the code (assuming "=" instead of "==") will show always the tab if TextFieldName isn't empty, removing that line will show/hide the tab according to show parameter value
It seems to work when I run it but I'm not sure what you'd expect it to do so it might not be working the way you'd like it to. :)
function setVisibleTabSection(tabName, textFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabName);
if(!tab) return;
if (!TextFieldName)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(textFieldName).getValue();
if (section)
tab.setVisible(true);
}
}

How to add a Calculated field to AllContentType?

Today, I'm having a problem is after I had created a Calculated field. It seems there is no way to add AllContentTypes. And the DefaultView, maybe I can handle this. And I also saw this method:
spList.Fields.AddFieldAsXml(spFieldUser.SchemaXml, True, SPAddFieldOptions.AddToAllContentTypes);
But in this case, I'm not sure I can use it or not. Because my code is:
//SPField tempSPField = spList.Fields.CreateNewField(createSPColumnObject.ColumnType, createSPColumnObject.ColumnName);//We can not use this code line for creating Calculated (there is no constructor for this)
SPFieldCollection collFields = spList.Fields;
string strSPFieldCalculatedName = collFields.Add(createSPColumnObject.ColumnName, SPFieldType.Calculated, false);
if (createSPColumnObject.IsAddedToDefaultView)
{
SPView spView = spList.DefaultView;
spView.ViewFields.Add(strSPFieldCalculatedName);
spView.Update();
}
SPFieldCalculated spFieldCalculated = null;
//
spFieldCalculated = (SPFieldCalculated)collFields[createSPColumnObject.ColumnName];
spFieldCalculated.ShowInDisplayForm = true;
//spFieldCalculated.ShowInEditForm = true;
spFieldCalculated.ShowInListSettings = true;
//spFieldCalculated.ShowInNewForm = true;
spFieldCalculated.ShowInViewForms = true;
//
spFieldCalculated.Description = createSPColumnObject.ColumnDescription;
spFieldCalculated.Formula = string.Format(#"={0}",createSPColumnObject.CalcFormula);
spFieldCalculated.Update();
//spList.Fields.AddFieldAsXml(spFieldCalculated.SchemaXml, createSPColumnObject.IsAddedToDefaultView, SPAddFieldOptions.AddToAllContentTypes);// also use this code line because we will get an exception with a duplicate column ID.
spFieldCalculated.OutputType = SPFieldType.Text;
spList.Update();
I totally created a Calculated column but how can I add it to allcontent types ? everybody could help me out this ? BTW, to the DefaultView, I did like the above is right ? Could eveybody let me know this ?
I just worry about everybody get misunderstanding ? Or review with missing code. So could everybody please to take a look on my code clearly ? Thanks all.
Many thanks, :)
Standley Nguyen
I'm not sure if i fully understand what you are trying to do however i may be able to shed some light on some parts of what you are trying to do.
When you create your field does it then appear in your site actions -> site settings -> Site columns. If so you have created this correctly. If it doesn't there are hundreds of examples of how to do this if you search google.
Once you have your field create you then need to consider which content types you want to add it to. Once you have these content types you then have to add something called a field link to the Content type.
This isn't my code i have picked it off the web but this should do what you require.
SPContentType ct = web.ContentTypes[contentType];
ct.FieldLinks.Add(new SPFieldLink(field));
ct.Update();
Cheers
Truez

Resources