How to use shouldSelect on Hint for React-Bootstrap-Typeahead to detect "enter" and "," keystrokes - react-bootstrap-typeahead

I have been trying to figure out a way to select hint on "Enter" or "," keystroke but am unable to find any documentation on it. Additionally, I get the following warning, during compilation "Warning: [react-bootstrap-typeahead] The selectHintOnEnter prop is deprecated. Use the shouldSelect prop on the Hint component to define which keystrokes can select the hint." Is there any examples on how to use the shouldSelect on 'Hint'?

The shouldSelect prop has the following signature:
(shouldSelect: boolean, SyntheticKeyboardEvent<HTMLInputElement>) => boolean
You can use it to define the conditions under which the hint should be selected. In your case you'd want something like the following:
<Hint
shouldSelect={(shouldSelect, e) => {
// Select the hint if the user hits 'enter' or ','
return e.keyCode === 13 || e.keyCode === 188 || shouldSelect;
}}>
...
</Hint>
Here's a working example: https://codesandbox.io/s/rbt-shouldselect-example-51s7n

Related

ZKOSS version 7.0.0 checkbox or clear radiogroup

Good morning, everyone,
I am having a problem with the handling of two checkboxes which should be mutually exclusive, on the page we cannot put an id because multiselection is provided.
enter image description here
Here the zkoss code:
<cell colspan="2">
<checkbox
label="${labels.label.giaAddebitata}"
checked="#load(each.flagAddebitata eq '1')"
onCheck="#command('addebitata', fladd=event.checked,idPer=each.idPerizia )"
onFocus="#command('manageList', idPer=each.idPerizia)"
disabled="#load(each.statoContabile eq 4 ? true : false)"/>
</cell>
<cell colspan="2">
<checkbox
label="${labels.label.nonAddebitare}"
checked="#load(each.nonAddebitare eq '1')"
onCheck="#command('nonaddebitata',flnoadd=event.checked, idPer=each.idPerizia)"
onFocus="#command('manageList', idPer=each.idPerizia)"
disabled="#load(each.statoContabile eq 4 ? true : false)"/>
</cell>
and the java functions
#Command
#NotifyChange ({ "flagAddebitata","nonAddebitare", "selectedRic"})
public void addebitata(#BindingParam("fladd") boolean fladd,#BindingParam("idPer")int idPerizia ) {
boolean addebitata = fladd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setFlagAddebitata(booleanToString.apply(fladd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("addebitata funzione " +addebitata);
}
#Command
#NotifyChange ({ "nonAddebitare", "selectedRic"})
public void nonaddebitata(#BindingParam("flnoadd") boolean flnoadd,#BindingParam("idPer")int idPerizia ) {
boolean nonaddebitata = flnoadd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setNonAddebitare(booleanToString.apply(flnoadd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("nonaddebitata funzione " +nonaddebitata);
}
We tried using the && != " the != alone and adding another binding param to the java functions.
The result we want to achieve is that if one check is clicked the other if it is already selected loses the check.
Alternatively we tried the radiogroup but it does not allow the non-selection of radioboxes, one is always mandatory.
Is there a way to clear the radiobutton without a java clear function?
Thanks
That's a lot of code and hard to turn into a reproducing case due to all of the extra objects, so I'll focus more on the functional requirement.
From your description, I understand that what you want to create is a system in which you can either select "A", "B" or "none".
There is some unspecified behavior in there (like if "A" is selected, can I select "B" and automatically clear selection on "A"? Or does having "A" selected mean that "B" is non-selectable).
From your stated requirement, the component I would choose to express that structure is a dropdown menu with 3 choices ("not selected", "A", "B"), but that might not be what you are trying to achieve with the UI design here?
If you want to make something like that using checkboxes, you may want to keep a single state for the selection status, and a command to update the selection status.
See a simple code sample here: https://zkfiddle.org/sample/hb7f7k/1-Another-new-ZK-fiddle
The left 2 checkboxes work on a "unselect others if selected" workflow.
The right 2 checkboxes work on a "cannot select others while selected, but can unselect" workflow.
Note: that sample is a "bare minimum" implementation. In a real case, you'd improve it by factorizing the code, making it into a template, etc. rather than declaring these values inline.

how to use prevent default on Elm Browser.Event.onKeyDown

Please Note: I could not a find a solution that could work here, so I used ports for the same.
I need to use Browser.Events.onKeyDown for which I have also written a decoder, I need to create some shortcuts for my web app thus I need to prevent default behavior of Meta key (on Mac) and Ctrl key (on other Os)
In my Subscription method I am using the following.
But there is no exposed way of using prevent Default.
let
decoder : Decode.Decoder Msg
decoder =
keyDecoder
|> Decode.andThen
(\( keyCode, ctrlKey ) ->
case keyCode of
39 ->
Decode.succeed <| ShortCutNext
37 ->
Decode.succeed <| ShortCutPrevious
_ ->
Decode.fail ""
)
in
Sub.batch
[ Browser.Events.onKeyDown decoder]
keyDecoder : Decode.Decoder ( Int, Bool )
keyDecoder =
Decode.map2 (\a -> \b -> ( a, b ))
(Decode.field "keyCode" Decode.int)
(Decode.field "metaKey" Decode.bool)
Note: The event is on the page itself and not on any element such as textarea thus Html.Events.custom "keydown" options decoder is not applicable.

Xamarin.UITest-How to verify element is enabled or disabled

I am new to xamarin uitest, can any one please help me out how to verify the element is enabled or disabled with an example.
Thanks in advance.
Assuming that you are using Xamarin's Repl then you can use the following
app.Query(c => c.Id("ElementID")).FirstOrDefault().Enabled
Repl will then return whether the element's enabled property is either true or false
From this, then you can then assign that line to a variable and assert against it
var elementEnabled = app.Query(c => c.Id("ElementID")).FirstOrDefault().Enabled;
assert.AreEqual(true, elementEnabled);
I didn't really understand your question, but if what you're asking for is how to check if a toggle button is enabled, then you can go that way :
internal void SetToggle(string id, bool setToggled)
{
if (setToggled != IsToggled(id))
app.Tap(e => e.Property("id").Like(id));
}
internal bool IsToggle(string id)
{
return app.Query(e => e.Property("id").Like(id).Invoke("isChecked").Value<bool>())[0];
}

Dynamic form validation with RxAndroid

I'm developing an Android application. I would like to use RxAndroid for form validation. I have done a lot of research on the internet but did not find a guide to take me through. Please help me out with how i can go about with the same, possibly with a small example. Thank you.
I found this tutorial, looks great: Reactive Forms with RxAndroid
First, add RxBinding to your project
RxBinding has a built in method for doing this,
RxTextView.textChanges(). It takes a EditText and returns an
Observable emmitting a CharSequence on each character change.
mInputLayout.setError("Invalid Credit Card Number")
Observable<Boolean> creditCardObservable = RxTextView.textChanges(mCreditCardInput)
.map(inputText -> (inputText.length() == 0) || inputText.toString().matches("credit card regex here"))
.distinctUntilChanged();
creditCardObservable.subscribe(isValid -> mInputLayout.setErrorEnabled(!isValid));
Repeat the process with more values, like:
mCreditCardInputLayout.setError("Invalid Email);
Observable<Boolean> emailObservable = RxTextView.textChanges(mEmailInput)
.map(inputText -> (inputText.length() == 0) || inputText.toString().matches("credit card regex here"))
.distinctUntilChanged();
emailObservable.subscribe(isValid -> mCreditCardInputLayout.setErrorEnabled(isValid))
And then we can enable the button when the values are valid:
Observable.combineLatest(
creditCardObservable,
emailObservable,
(creditValid, emailValid) -> creditValid && emailValid)
.distinctUntilChanged()
.subscribe(valid -> mSubmit.setEnabled(valid));
Optional retrolambda library

Lift - how to get default value of select using WiringUI

I have an issue with getting default value of select dropdown.
i have fruits val:
val fruits = List("apple", "banana", "other")
and i render a tr with:
<tr id={ theLine.guid }>
<td>
{
SHtml.ajaxSelect(fruits, Full(fruits(0)),
s => {
mutateLine(theLine.guid) {
l => Line(l.guid, l.name, s, l.note)
}
Noop
})
}
</td>
(...)
on page html is rendered correctly with option selected="selected", but when i try to save it to DB i get empty value of fruit. if i change option to 'other' and then i select it back to 'apple', it saves right value.
i add also a println function to addLine to see what values are in this vector, and there is empty value if i dont change fruit option, so i suppose that it is not problem when i process lines to save it to DB.
can you help me with this?
thanks
Gerard
Before you change your select option, you are not triggering the event that calls your function. The function is bound to onChange and that only gets fired when the value changes.
To fix, you could either: Start with an option like "Select a value". This would require the user to change the item, but is the only way to trigger the onchange.
If you don't want to do that, you could add a button and add your logic to a button click handler that would get called when submitted. Something like this should help - you'll need to bind it to your output, either inline as you provided, or via CSS Selectors:
var selected = Full(fruits(0))
SHtml.ajaxSelect(fruits, selected,
s => {
selected = Full(s)
Noop
})
SHtml.ajaxSubmit("Submit", () => {
mutateLine(theLine.guid) {
l => Line(l.guid, l.name, selected, l.note)
}
})