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.
Related
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.
I currently have nouislider working fine. However I would like to add a postfix "%" symbol to my input fields, to show the user that the value is a percentage value, and the problem I'm having is that the value being passed with the form includes the % symbol. Does anyone know a workaround so that only the value is passed with the form?
An alternative method that I tried, to the format:wNumb method suggested in the nouislider documentation is as follows:
slider.noUiSlider.on('update', function( values, handle ) {
moistureValues[handle].value = values[handle] + '%';
});
However this is still appending the percentage symbol to the url. Is there any other way that would solve this problem? Thanks
The value of the input is the value that is submitted, this is how the basic feature in HTML works. You have some options:
Place the % sign in a <span> after the input.
use addEventListener('submit', ...) on the form, capture the submit, then change the input value and re-submit it (using .submit()).
Displaying the entire value in a span, and using a separate (hidden) input for the submit value.
(disclosure: I'm the lead developer for this libary).
You are changing the value while you only need to change the style of the element:
connectBar.style[side] = offset + '%';
Full example:
var connectSlider = document.getElementById('connect');
noUiSlider.create(connectSlider, {
start: [20, 80],
connect: false,
range: {
'min': 0,
'max': 100
}
});
var connectBar = document.createElement('div'),
connectBase = connectSlider.getElementsByClassName('noUi-base')[0],
connectHandles = connectSlider.getElementsByClassName('noUi-origin');
// Give the bar a class for styling and add it to the slider.
connectBar.className += 'connect';
connectBase.appendChild(connectBar);
connectSlider.noUiSlider.on('update', function( values, handle ) {
// Pick left for the first handle, right for the second.
var side = handle ? 'right' : 'left',
// Get the handle position and trim the '%' sign.
offset = (connectHandles[handle].style.left).slice(0, - 1);
// Right offset is 100% - left offset
if ( handle === 1 ) {
offset = 100 - offset;
}
connectBar.style[side] = offset + '%';
});
See the example here: https://refreshless.com/nouislider/examples/#section-custom-connect
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);
}
}
I have four fields. Lets call them a, b, c and d. I need to validate them.
Error is when:
One til three fields are not empty;
Error is not when:
All fields are not empty,
All fields are empty;
Any neat solution here? Thanks in advice.
Edit:
Only relationships are that all four variables are prefixed with event_. It gives me event_name, event_description etc..
Edit #2:
At the moment I have something like...
if (
!empty($values['event_date'])
&& !empty($values['event_time'])
&& !empty($values['event_name'])
&& !empty($values['event_description'])
) {
It checks that all fields are filled up and then, if that's true, adds event.
As I said before, I need to display user-friendly error when some field isn't filled up (for example, user had forgot to enter description). Anyway, when all fields are filled up (it means - all okay) or when no fields are filled up (it means - user ignores event adding and don't want to add one) - no error should be displayed.
I could write code with 16 'if' statements, but isn't there any better way? :)
This isn't beautiful, but as long as you have something unique about the fields you want to check (such as "event_..."), you could loop through the variable array ($values, $_POST, etc) and check only the fields that matter. Then, you can easily check for an all or none situation.
Here is a quick example:
$total = 0;
$filled = 0;
foreach($values as $field => $val) {
if(strpos($field,'event_') === 0) {
$total++;
if( ! empty($val)) {
$filled++;
}
}
}
if($filled == 0 OR $total == $filled) {
//PASS VALIDATION
} else {
//FAIL VALIDATION
}
Is there a relationship between one of the entered values and the none entered values??
could you just parse it as an empty value?
if ( ! isset($post->a) ) $post->a = '';
I am working on the project where i had used choice group in form. Now I want to get the selected item or index number of the choice group and want to perform some action.
I had tried through this:-
System.out.println(cgPrefs.getString(i) + (selected[i] ? ": selected" : ": not selected"));
But I am not getting the exact index number of the selected item in choice group.
You will get flags according to selection
boolean[] selectedFlag = new boolean[getChoiceGroup().size()];
using getSelectedFlags() method
getChoiceGroup().getSelectedFlags(selectedFlag);//getChoiceGroup() returns object of choicegroup
Now iterate and print
for(int i = 0 ; i < selectedFlag.length; i ++){
if(selectedFlag[i]){
System.out.println("Selected : "+getChoiceGroup().getString(i));
}else{
System.out.println("Not Selected : "+getChoiceGroup().getString(i));
}
}