Bug when use value as children of TextInput [React Native] - ios

I'm having some problems using component in React Native 0.70.2.
Specifically I need to put the text like this {children} , instead of passing a value prop, because I need to manipulate text for creating a mention text input.
Here's a video of what happen: https://user-images.githubusercontent.com/64473929/194781923-7a314cef-6522-424d-a085-9a70478bd390.MP4
Here's my code: https://snack.expo.dev/#pietroputelli/bbbed6
Is there any path to solve this bug?
Thank you.

You should add
onChangeText={(text) => {
setValue(text)
}}
Now it will only rerender the text once per keystroke.
If you change the value directly like you do, the state will update first when you enter a keystroke, then the component rerenders, and will set the state again with the value+value, which will trigger rerenders exponentially.

Related

How to have conditional autofocus in Svelte 3

I would like to shift focus on my page in response to keyboard input. With Svelte it seems that the simplest way is to use the autofocus attribute. However I cannot get conditional autofocus attributes to work.
Here's a simple repro of my problem: https://svelte.dev/repl/0861d097921d4a35957f016a8c35cfe6?version=3.44.3
Am I doing something wrong or is this not possible in Svelte 3?
Conditional autofocus was possible in a previous version of Svelte according to this question: Sveltejs render html attribute conditionally
And conditionality is possible for other attributes in Svelte 3 according to this question: How to have a conditional attribute in Svelte 3?
One solution could be to add a key block around the thing to make it re-run on every update of the focusIndex.
Example
{#key focusIndex}
{#each items as item, index}
<input autofocus="{index === focusIndex}" value={item} on:keydown={(ev) => test(ev)} />
{/each}
{/key}
Not the prettiest solution, but might unblock you.
Not strictly an answer to the exact question I asked, but the alternative that I've gone with is to use bind:this on the elements to create an array of the DOM elements and then in the keydown handler explicitly call .focus() on the DOM elements.
Example: https://svelte.dev/repl/83934cd7924741a8a4c5a620f79d5bb5?version=3.44.3

how to change select2 value programmatically

I have a select2 box in bootstrap modal, I want to change the value of the select2 box but it didn't work.
I tried every single solution in previous posts and results but none of them got it work.
I use select2 4.0.2, I tested:
$('#select_id').val('val').trigger('change.select2');
$('#select_id').val('val').trigger('change');
$('#select_id').val('val').change()
It works one or two times then it stops working (randomly)
It works fine only when I change the select2 back to 3.x.x
$('#select_id').val('val').trigger('change');
is the right way, see here
$('#select_id').select2('val', selectedValue);
For Select2 with Ajax call, I struggled with lot of options, but none worked. Then i came to following solution, which works like charm
$("#select_id").html($("").val('val').text('text')).trigger("change");
To programmatically select an option/item for a Select2 control, use the jQuery
$('#mySelect2').val('1'); // Select the option with a value of '1'
$('#mySelect2').trigger('change'); // Notify any JS components that the value changed
You can also pass an array to val make multiple selections:
$('#mySelect2').val(['1', '2']);
$('#mySelect2').trigger('change'); // Notify any JS components that the value changed
I have used the following code in 4.x.xx version and it is working
$('#select_id').val('val').select2();
If you, like me, have added a custom handler for the select2:selecting event the correct complete answer to changing a value and triggering the custom select2 event would be:
$('#select_id').val('val').trigger('change').trigger({
type: 'select2:event_name', // It worked for me with select2:selecting and select2:select
params: {
args: { // Only use 'args' if using select2:selecting, select2:select does not use it
data: varWithEventData
}
}
});
For those who facing an issue like this:
If you're using multiple select elements and have a common event handler (like $(".mySelect2Inputs").click(...) ) when you do $('#mySelect2').trigger('change') the click event handler is gonna trigger multiple times ($(".mySelect2Inputs").length times).
To prevent this situation, you must use $('#mySelect2').trigger('change.select2') (attention to .select2 namespace!).
From the select2 docs:
https://select2.org/programmatic-control/events#limiting-the-scope-of-the-change-event
It's common for other components to be listening to the change event, or for custom event handlers to be attached that may have side effects. To limit the scope to only notify Select2 of the change, use the .select2 event namespace:
$('#mySelect2').val('US'); // Change the value or make some change to the internal state $('#mySelect2').trigger('change.select2'); // Notify only Select2 of changes

Jquery UI tag-it widget - what's the best way to disable entries?

For the Jquery UI tag-it widget, I'd like to disable text input into the class="ui-widget-content ui-autocomplete-input" textbox which contains all the tags.
My purpose is to just allow certain people the ability to delete inappropriate tags, but not allow anybody to add tags (which are auto-generated).
Is the best thing for me to edit the tag-it .js file and add a disable="disable" for that field? If I do that, won't that prevent the contents of that field from being submitted? Or does that matter as long as the associated hidden field is submitted?
Or is there a better way of doing this (an overriding style?) without modifying the tag-it file itself?
Thanks,
doug
In tag-it.js I replaced this line:
this._tagInput = $('<input type="text"').addClass('ui-widget-content');
with this:
this._tagInput = $('<input type="text" readonly="readonly"/>').addClass('ui-widget-content');
adding the readonly="readonly" attribute. That had the desired effect of preventing input but still allowing users to delete inappropriate auto-generated tags.
I had the same question as original op.
But as the question is 2 and a half years old, and tag-it version is changed.
The accepted answer needs to be updated to the folowing in
tag-it.js around line 478:
from:
if (this.options.readOnly){
tag.addClass('tagit-choice-read-only');
}
To:
if (this.options.readOnly){
tag.addClass('tagit-choice-editable');
// Button for removing the tag.
var removeTagIcon = $('<span></span>')
.addClass('ui-icon ui-icon-close');
var removeTag = $('<a><span class="text-icon">\xd7</span></a>') // \xd7 is an X
.addClass('tagit-close')
.append(removeTagIcon)
.click(function(e) {
// Removes a tag when the little 'x' is clicked.
that.removeTag(tag);
});
tag.append(removeTag);
}
This is under the documentation of git repository having the documentation, under the Properties section:
$("#myTags").data("ui-tagit").tagInput.addClass("fancy"); //Obviously
if you want to do something with class...
This translates to the solution for this below, in my personal implementation style, and probably the only way I could get this to work:
$("#myTags").data("ui-tagit").tagInput.prop('disabled' , true);
This is if I understand your question correctly.
Note: ReadOnly does not make the tags un-editable.
As far as going through the tags, you could use ..
var x = $("#myTags").tagit("assignedTags");
Make it as an input field, and that ensures its "singleFieldNode" meaning tags are , (comma) separated. That way you can parse through it (split for commas(,) into an object, or however you want to do it)
PS: To apply any of the snippets above, simply change to the "id" of the HTML element that contains TagIt, and your code would work correctly.
JQuery TagIt v2.0

Clearing jQueryMobile DateBox value from an event

I have 2 DateBox (from & to). What I want to do is whenever I click on the "from" DateBox it will always clear the "to" DateBox.
I'm looking at the doclear method and I'm not sure if it is the right one or even know how to use it.
Just to be clear I'm using this.
Any help would be appreciated. Thanks!
In my testing setting the value of the box to an empty string ('') works.
Assuming id of fromDate and toDateon the two boxes the following code should do the trick:
$('#fromDate').click(function(){
$('#toDate').val('');
}

How to implement a toggle button to set a Rails boolean field

I have a Rails form with a checkbox on a boolean field.
I want to replace the checkbox with a toggle button, using Twitter Bootstrap.
Is there anything baked into Rails to provide this kind of functionality? Or will I need to write a script to update the checkbox value when the toggle button is clicked?
Thanks for any pointers. After a lot of searching, I've been unable to find anything that describes this.
At this point in time, the toggle Bootstrap buttons do not have the correct markup to work out of the box with forms (source).
You can wrap around the controls to insert the correct values into your parameters map using hidden fields. If you're using AJAX requests, you can simply include them in your parameters there.
In the case of the single toggle, you could implement a function as simple as this to set the hidden value.
In your form:
<input name="toggled" value="false" />
Evaluated before submission:
function isToggled() {
$('input[name="toggled"]').value($('#toggleButton').hasClass('active'));
}

Resources