I have a class with a TextField as a property. This text field is added to the stage and has a digit as a value of the text property. I also have a method, that must change this digit:
public function decrementCooldown()
{
cdText.text = (--cd.value != 0)? cd.value : "";
}
However, it changes nothing. I've modified the code that way:
public function decrementCooldown()
{
cdText.text = (--cd.value != 0)? cd.value : "";
cdText.x -= 100;
}
This caused my text field to move to the left, but its text remained the same.
Then, I've tried to trace the text before and after modifying it. The second line of the output contained the digit that I wanted to appear on screen, it was 1 less than the digit on the first line.
I wonder how to solve my problem.
Ok, this seems really strange to me, but the problem was with DropShadowFilter I had on the TextField.
I've fixed this problem by adding two lines that clear the filters array before modifying the text, then adding a DropShadowFilter again after that:
public function decrementCooldown()
{
cdText.filters = [];
cdText.text = (--cd.value != 0)? cd.value : "";
cdText.filters = [new DropShadowFilter()];
}
Seems like a bug though.
Related
I am trying to use the toolbar search feature to search through a number of SwipeableContainers. Each container has a MultiButton on top and a number of buttons bottom left and bottom right. Essentially I receive data from a database and loop through the result adding a SwipeableContainer and set each one with a name (Line1 of the MultiButton) using sc.setName(). I then attempt to search using the code below:
Here is the code:
hi.getToolbar().addSearchCommand(e -> {
String text = (String)e.getSource();
if(text == null || text.length() == 0) {
// clear search
for(Component cmp : centercont) {
cmp.setHidden(false);
cmp.setVisible(true);
}
centercont.animateLayout(150);
} else {
text = text.toLowerCase();
for(Component cmp : centercont) {
SwipeableContainer sc = (SwipeableContainer)cmp;
String scName = sc.getName();
boolean show = text.length() == 0 || scName.toLowerCase().contains(text);
sc.setHidden(!show);
sc.setVisible(show);
}
centercont.animateLayout(150);
}
}, 4);
After I input the first character into the search I get this exception: java.lang.ClassCastException: com.codename1.ui.Label cannot be cast to com.codename1.ui.SwipeableContainer. If I press 'OK' past the error dialog, the search filters the options as expected for that 1 character. I get the same exception and result for the next character and so on.
I would appreciate some guidance on where I have gone wrong.
You have more than one component within centercont. One of them is a SwipeableContainer and the other is a Label.
You can workaround it by checking with instanceof before doing the cast but you might want to check your code/component inspector to see what's that label and if it should be there.
Now I get a ComboBox control, everything is OK except that:
firstly, I selected one in a multiple-selection list box, works;
secondly, I edit the selected text, no update,
thirdly, I edit again then changed as I wanted.
At my program, every time selecting and editing would call a function named ChangeControlNotify(ClistControl* pControl) and there is a GetTest() in this function. The problem occurred at that function GetTest() because it calls CComboBox::GetCurSel. GetCurSel function should return -1 at first time edit, but it returns the selecting line number as that firstly selecting.
Does anyone know why? I think maybe there is still a handler reminding after firstly editing. But I don't know and have no idea yet. If some kindly guys help. very aprreciate. Thanks
_bstr_t CComboBoxListControl::GetText()
{
CComBSTR bstr;
int nSel = m_comboBox.GetCurSel();
if ((-1 == nSel) && ((m_comboBox.GetWindowLong(GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWNLIST))
{
m_comboBox.GetWindowText(&bstr);
}
else
{
m_comboBox.GetLBTextBSTR(nSel, bstr.m_str);
}
return bstr.m_str;
}
template <bool bIsCheckListView>
void CRichListControls<bIsCheckListView>::ChangeControlNotify(CListControl* pControl)
{
CListPosition lp = FindControlPosition(pControl);
SetItemText(lp.GetLine(), lp.GetColumn(), pControl->GetText(), false);
CRichListControlData data(m_hWnd, lp);
SendMessage(m_wndContained.m_hWnd,
WM_RICHLISTCONTROLS_MESSAGE,
WPARAM(rmtModify),
reinterpret_cast<LPARAM>(&data));
}
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;
}
}
}
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 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.