angularjs same textarea to edit multiple elements - textarea

I have this case where I set a current item from a list and I need to use a textarea to edit that element's value.
Because of some constraints I have to use a keyup event but I don't think that's a problem.
Check this fiddle: http://jsfiddle.net/terebentina/Euj2C/
click on first/second buttons - it works, it changes the text in the textarea to the value of each element.
change the text in the textarea to something
click on the first/second buttons again - the textarea is not updated anymore. If you look in console, you can see that it switches between the elements, it's just that the textarea is not updated anymore.
Any suggestions? this is driving me nuts!

I know there is a better way modifying your directive to do this but as a quick fix for now you can try binding your textarea to a ngModel value that is just a copy of the current text in the selected element:
<textarea keyup="" ng-model="keyupText"></textarea>
With this in as your current function:
$scope.current = function(idx) {
$scope.current_element = $scope.elements[idx];
$scope.keyupText = $scope.current_element.value;
console.log('current is', $scope.current_element.value);
}
See this fiddle for an example.

Related

how to set setNextFocusDown in TextArea

I am try to use setNextFocusDown method in TextArea eg:
textArea.setNextFocusDown(nextTextField);
But in keyboard it does not show next button so how to set setNextFocusDown in TextArea ?
This will only apply if you do it in the beginning and only for TextArea subclasses. Notice this hint will not apply for every case.

Update select2 option text on-the-fly?

I want to change an option's text on the fly. The HTML can be changed easily by:
$('option[value=custom-pub]').text("New Text For Pub");
How can I force select2 to refresh the text? I don't want to destroy() and create the select2 object from scratch, because I want the user selection to stay selected.
Simply
$("select").select2();
works.

Button on jQuery UI

I am writing a script using jQueryUI's button http://jqueryui.com/dialog/#modal-form.
The button is pretty fancy looking.
Now, when I tried to use jQuery to change the display name of the button:
$('#signin').text("new name");
The Button revert to the original style of the browser, with no padding and etc. I don't know why change of style happens when I just change the display name of the button. Please suggest me a way to fix it.
To change button text use this :
$('#btnId').val('new-text');
I figured out how. I used a span tag around the display name and just change text of that span tag.

JqueryUI tagit - how can I suppress the new entry text field from appearing?

For the JqueryUI tag-it widget, I'd like to completely prevent the new extra text entry field from appearing. I'm pre-populating with existing tags, and I'd just like to allow people to delete tags but not enter them.
I can make the new field read-only, but the field remains visible in IE and in both IE and Firefox clicking in the area of the widget causes the cursor to focus on that field.
What I'd like to do is get rid of the extra input field altogether.
There doesn't seem to be a tagit property for this associated with the .tagit() method. Is there something else I can do to prevent the extra field from being created?
Thanks,
doug
Try this:
$('#tagit').tagit({
//options
}).ready(function() {
$(this).find('.tagit-new').css('height', '13px').empty();
});
Using firebug we can see that the input field created by tagit is in a li element with class tagit-new. We need to set the height otherwise the tag container will squash to a slither when the last tag is deleted, and then we can empty() this to get rid of the tag input field.

OnClick increase textarea rows

Id like to have a smiple html textarea that when clicked (i guess onFocused) will change its rows="1" property to rows="10." I am pretty sure this can be done with javascript, but im not sure how. Any help will be much appreciated.
<textarea rows="1" onclick="this.rows = '10';"></textarea>
If you want to increase number of rows when textarea is selected by another way for e.g. tabulator you should use onfocus instead of onclick, and if you wanna decrease rows when losing focus, you should use something like this onblur="if(this.value == '') this.rows = '1';" - Because when you once type text into the textarea, and click out of it, the textarea may shrink to 1 row and your text will be not readeable. This prevents this behavior - only shrink when textarea is empty.

Resources