Two AutoCompleteTextField in same form - codenameone

I have 2 AutoCompleteTextFields in a form (database linked). The two of them are initialized with .setText(value) and then i show the form.
Then i noticed that the filter event is fired when i initialize them and when i show the form. I don't know if this the standard behaviour or if i am doing something wrong.
Can i somehow disable this first and second filter event call?
Besides that, it throws some Java null errors too. If i take out of the form the first or the second autocompletetextfield no error is shown.

Filter is called initially to indicate that data has changed and initialize the data. You can create your own special case (e.g. first time) and do nothing there.

Related

After reloading CN1 Form, GUI elements stop working properly

Our app allows users to submit data to our servers.
Sometimes, users will need to make 3 submission in a row. After checking that the submission works properly (and thankfully it does), we call CustomForm().show() and the Form shows correctly. (CustomForm obviously extends Form.)
We use InteractionDialogs, just as in all other iterations, to handle validation by providing feedback to the user. We do so to mimic the Android Snackbar that provides a prompt and a Button to do an action. In the 1st 2 iterations, the InteractionDialogs show and dispose properly; in the 3rd iteration, the InteractionDialogs start acting erratically.
We also noticed that once that CustomForm (or any other submission forms) is shown 3 times (either the same Form 3 times in a row, or any combo of our submission forms 3 times altogether), a different Form displaying a BrowserComponent will fail – the BrowserComponent will not show anything at all, despite using a strong, unfiltered internet connection and having worked properly prior to the submissions being done. Neither the app nor the Form housing the BrowserComponent crashes -- the BrowserComponent simply does not show anything.
Is there a limit on how many instances of a given Form can be shown, or is there a memory issue?
Please, any ideas on how to solve this?
Thank you.
EDIT: I am adding a screenshot of the EDT thread -- it seems to have invokeAndBlock() called twice and then wait() is called, even though I wrapped my call to show the Form with the BrowserComponent with this try-catch:
try {
CN.invokeWithoutBlocking(() -> {
new FormWithBrowser().show();
)};
} catch (BlockingDisallowedException ex) {
e.getMessage();
}
The other issue is how do I fix InteractionDialogs in my submission form from being affected by invokeAndBlock() and wait() as well? I also don't get any BlockingDisallowedExceptions in my logs. Does that mean that wait() is really the issue?
Thanks again.

Fire DTM rule after certain seconds

This is one of the scenarios suggested by our clients which includes firing DTM rule after certain time.
Scenario - As per the requirement, once the website is loaded, and the user does not perform any activity, a page load rule must be fired after 5 seconds. In case a user performs a click or any other action before 5 second, then that particular tracking rule must be fired.
Any suggestion on how should i go for this one.
This is meant to be a PoC, a starting point. You will need to expand on this based on what you define.
As mentioned in my comments on your question, you need to define what "website is loaded" actually means to you (in a way that can actually be coded), and also define what constitutes a user action (also in a way that can actually be coded).
As a Proof of Concept (PoC), I will define "website is loaded" as the window.load event, and "click or any other action" as "clicks on any link".
Also, you weren't entirely clear on what you want to actually trigger. Near as I can tell, you want to trigger the same thing no matter what, and have stated no difference otherwise. So I'm going to make this PoC simplified accordingly, by calling a single Direct Call rule exposing a message signifying which scenario happened.
Part 1 - Timeout
A Page Load Rule is created and set to trigger on the window.load event. When that happens, a setTimeout is called, which will call a function after 5 seconds have passed. When the function iscalled, it checks if a Data Element called "fiveSecondRule" exists. If it does not exist, then it sets it to a value "timeout" to signify it was set from this code. Then a Direct Call rule named "fiveSecondRule" (defined below) is called.
Instructions
First, go to Rules > Page Load Rules, and click Create New Rule. Give your rule a Name of "Five Second Rule - Timeout".
Under Conditions, set the Trigger rule at dropdown to "Onload".
In the Javascript / Third Party Tags section, click Add New Script to open up a script overlay. Name it "config". For Type, select "Non-Sequential Javascript", and select/check the Execute Globally option.
Add the following code to the code box:
window.setTimeout(
function() {
if (!_satellite.getVar('fiveSecondRule')) {
_satellite.setVar('fiveSecondRule','timeout');
_satellite.track('fiveSecondRule');
}
}
,5000
);
Click Save Code and then Save Rule to save the rule.
Expanding the PoC
This is what you will need to alter if your definition of "website is loaded" is something other than window.load event. For example you may instead define it is DOM Ready, in which case you can simply change Trigger rule at to "DOM Ready". However, if your definition is more complex (e.g. waiting for some callback from your site's framework), then you will need to instead put this into a Direct Call rule and explicitly call it yourself.
Note: There is an Event Based Rule of "time passed" Event Type, that you can set to trigger after 5 seconds. As an alternative to the PoC you can do this instead, and add a rule condition similar to described in Part 2 below (instead of code above). The DTM documentation does not detail when the timer actually starts or how it actually keeps track of time for this event.
I haven't really spent much time trying to reverse engineer the core DTM library, but from 5 second eyeballing of it, near as I can tell it "registers" events of this type sometime during "Top of Page" code execution (where DTM Header script is placed), and it uses a cookie/localstorage and a timeInterval to constantly poll it.
So if this all fits your definition of the 5 second rule, it's a little bit less coding to make a 5 second Event Based Rule instead. But I chose the Page Load Rule and setTimeout method above to provide you more flexibility as a baseline, should your definition be more complex.
Part 2 - User Actions
An Event Based Rule is setup to trigger whenever the user clicks on a link. When the rule triggers, the condition code checks if the Data Element named "fiveSecondRule" is set. If not, then a value of "linkClick" is set to signify a link was clicked. Then the Direct Call rule named "fiveSecondRule" is called.
Instructions
Go to Rules > Event Based Rules and click Create New Rule. Give your rule a Name of "Five Second Rule - Link Clicks".
Under Conditions > Event > Event Type, select "click" (should be the default option).
Then For Tag > Element Tag or Selector, add "a" (no quotes).
Note: It's beyond the scope of this post to get into, but depending on what other code is implemented on your site/page, you may need to change some of the other settings in this section.
Next, under Rule Conditions > Criteria, select "Data> Custom" and click Add Criteria. In the Custom code box, add the following code:
if (!_satellite.getVar('fiveSecondRule')) {
_satellite.setVar('fiveSecondRule','linkClick');
_satellite.track('fiveSecondRule');
}
return true;
Click Save Rule to save the rule.
Expanding the PoC
As mentioned, this just covers clicking on links. It sounds like your definition of "action" includes more than that. Once you define what constitutes a user action, create more Event Based Rules accordingly.
Part 3 - Trigger
A Direct Call Rule is setup to act as the "trigger". All rules from Part 1 and Part 2 will ultimately call this rule, and this is where you place the code you want to execute whenever a user performs an action before 5 seconds, or when the 5 seconds pass.
Instructions
Go to Rules > Direct Call Rules and click Create New Rule. Give your rule a Name of "Five Second Rule - Trigger". Under Conditions > String, add "fiveSecondRule" (no quotes).
From here, you can trigger whatever tools you have implemented, or add whatever 3rd party tags you want to trigger. You can use %fiveSecondRule% syntax in the tool fields and it will have a value signifying how it was invoked (e.g. "linkClick" or "timeout", shown above). For javascript syntax (in js code boxes) you can use _satellite.getVar('fiveSecondRule') to get the value.
Expanding the PoC
I suppose it's within the realm of possibilities you may want to trigger separate Direct Call Rules depending on whether it triggers before or after 5 seconds are up. But that really depends on what you are ultimately looking to trigger, which you haven't clarified.
But if so, then rename this Direct Call Rule to "Five Second Rule - Before" and for the Condition, change it to "beforeFiveSecondRule" (no quotes). Also, go back and change the _satellite.track() call argument to this, for all rules you made from Part 2.
Then, create another Direct Call Rule named "Five Second Rule - After", and for the Condition, put "afterFiveSecondRule" (no quotes). Also, go back and change the _satellite.track() argument in Part 1 to this.

Inserting text into input in descendant component with React

I'm diving into react for the first time but I'm having some difficulty with a particular requirement. I have the following component structure:
Survey
--QuickTextOptions
----QuickTextOption
--Question
----Answer
------TextAnswer
As you probably can tell, I'm working on a survey application. A survey author would create a question, then answers (i.e. sub questions or options). There will be a number of different answer types including checkbox and text.
Also at the top of the survey, above the questions, are a list of "quick text" options. When one of these is selected, some text is appended to the value field of the appropriate TextAnswer's input field. A user can select as many of these as they'd like.
This is trivial to do with just javascript, but I can't figure out a good way to do this with React without adding refs to components down the chain of the survey.
If I pass it in as a prop, have AnswerText as a controlled component, and set value={this.state.value + this.props.quickText}. It just re-inserts the text on the handleChange event of AnswerText.
I'm considering using refs and calling child functions from parents but refs seem to be discouraged and I'll have to do this for Question, Answer, and AnswerText in order to pass it down the chain which seems a bit too much.
Is there any other way to fire an event to a descendant down the chain with some data? It's a one time addition so props seem to not work well for this.
Do you use something like FLUX and global state? In my practice, usually you build such app working around global state which stores your input data. This way you can edit it transparently from different places according to action events (the only ones which can modify that input value, inputs themselves are not doing that).
So I see that it should look like this:
You pass references to global state object deep into your components and to your form's input.
When you start typing each new character triggers event to modify global state value for this input. You're getting updated value instantly in your component's props and component renders newly entered character.
When you want to modify input from some other component (by pressing button) you do almost the same. You click on button and it triggers event saying that global state value for that input should have "some string" added. Your input component receives callback with new props and renders this text instantly.
By saying event I mean special event which gets some value and inserts it into global state. Rest is done by framework.
Hope this will help you to design your app. The approach I described above is a short description of how Tictail Talk web chat client works now.

Backbone.Collection.each - Very strange behaviour

I'm currently experiencing very unusual behavior when using the each method of a Backbone collection. In my app, I allow users to edit existing models, which includes editing and adding a number of time constraints to that model. The model and its time constraints are linked with Backbone Relational. Every time the user clicks to add a new time constraint, I add a TimeConstraint model to the relationship without saving it. If a user then decides to cancel the edit, all new/unsaved TimeConstraints should be removed from the relationship. However, when I'm looping over my collection, it doesn't seem to perform the final iteration.
I constructed a jsfiddle to demonstrate this behavior here: http://jsfiddle.net/richardstokes/ZzFgZ/9/
The steps to follow are:
Click "Edit Policy"
Add 2 or more new time constraints using the "New Time Constraint" button
Cancel the edits by clicking "Cancel Edits"
You'll notice the console prints the starting length of the time_constraints collection and the finishing length, as well as intermediate lengths after removing unsaved models. It always seems to stop short and leave one item in the collection, even though they're all new/unsaved.
I would greatly appreciate if someone would help me with this problem, it's had me stuck literally all day.
You're removing items as the collection of timeConstraints is being iterated, which might be causing undefined behavior. Try first getting the list of new timeConstraints, then passing them as an array to remove():
var toRemove = this.model.get('time_constraints').filter(function (timeConstraint) {
return timeConstraint.isNew();
});
this.model.get('time_constraints').remove(toRemove);

Foursquare Updating

No, not another question that asks, "How can I make my messages flow like on Foursquare???"
What I want to know is, how they are getting their messages in the right order and timeframe.
Here's my situation. I have a proc that can get messages for a given day, and then return the selected result set to the web and have on the front end, my code show them and slide new ones on top. However, these "new" ones, aren't new ones, they are just the ones in the set that didn't initially fit on the page, although they "look new". Now what happens when I get to the end, and the set is empty finally...I make another call right?
Well this call is going to get, yes some ones they didn't see, but also all the ones they already saw.
What's a work around for this?
Thanks.
If you only want to show messages once, then persist the Id of the last message and use that as input into the proc on the second call, basically asking for any messages that came in since the last call.
re: Foursquare, I assume you are referring to the "recent activity" on their main page. They seem to call for 30 activities, then just cycle through them showing 11 at a time. They loop through a static list of 30. No second call that I can see.

Resources