I have a dijit.form.Select widget. It's tied to a data store, if that matters. It's filled with several options already. All I want to do is programmatically set its value. I can get its value using myWidget.attr('value') but if I try to do myWidget.attr('value', 5) for example (where 5 is one of the valid values), all it does is reset the widget to select the very first option, no matter what value I give it.
This seems to be a bug, and there aren't any tests or documentation which show how to accomplish what I want to. But is there some way, even if it's a dirty hack?
I'm using Dojo 1.4.0. Note that dijit.form.Select is the new name for dojox.form.DropDownSelect.
edit: I even tried resetting the widget with all new options, but it ignores the option which has selected = true and just selects the first option. There must still be a way though.
Even if your values are ints, if you set your integer to a string then this will work.
dijit.byId( 'my_select' ).attr( 'value', String( 5 ) );
Turns out it's a bug - if the option values aren't strings, it won't work (mine were integers).
Repost of my comment:
There is a test page here: dojo archive that you can mess with. Using fire-bug I used dijit.byId('s9').attr('value', 'CO') successfully on that page. That will set the "store-based" Select on that page.
But as you said I set it using a string and you were using integers so I didn't see the bug. Good catch.
Related
In our (hybris) shop some products have a yform to summarize the parts of the product. Is there an easy way to copy the value of the sum field into an other field (automaticly) like the productquantity (no yForm)?
I guess I need javascript, but the id of the sumfield is generatad, so I don't know how to get the sum. Also my Javascript abilities are quite limited...
UPDATE:
To get the value I use this part of code:
copyYFormValueToProductQuantity : function() {
var copyText = document.querySelector('input[id*="sum"]').value
if (copyText > 0 && copyText != null)
{
//do stuff
}
console.log("Copied value: " + copyText)
},
But this line
document.querySelector('input[id*="sum"]').value
returns null. If I use it in the browserconsole, it also returns null. But after I inspected the element it works and returns the value I want to. So I guess I am missing some JS-basics here and the object isn't ready before?
Btw.: I call this function with a keydown-eventlistener.
This can most likely be done from the jsp files. There you have all the data that is needed, so you most likely need to only copy that field where you need it.
We can also help you more if you add some code examples here (what exactly is that yform?). If you struggle to find where in code is that specific yform created/added, it's always worth giving a try to search for the applied classes of the html (search the entire project and see what you find).
As I understand your question, you are saying that you want to copy the value of a yForm field named sum into a non-yForm field named productquantity, and you are asking specifically about how to access the value of a yForm field from JavaScript. If I understand this correctly, you can do so by calling the following JavaScript API:
ORBEON.xforms.Document.getValue("sum");
You can find more about this and other related API on Client-side JavaScript API.
I'm going through the documentation for arangojs and looking at the function collection.update(), keepNull is one of the options that can be added. https://github.com/arangodb/arangojs/blob/master/docs/Drivers/JS/Reference/Collection/DocumentManipulation.md
When going through the same documentation for the function collection.save() (https://github.com/arangodb/arangojs/blob/master/docs/Drivers/JS/Reference/Collection/DocumentCollection.md) we find no such option. Why? Do I first need to have an original file, then update that one with keepNull: false before I get it to clean up my documents from any null valued keys? Or is this a lack in the documentation? I think it's correct since I haven't managed to set keepNull to false using collection.save myself.
The driver hands the query options over to the server, so this is the relevant documentation to look at:
https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document
The API does not support keepNull as option when creating a document. It is only available for UPDATE/REPLACE queries to mark attributes for removal. So it's up to you to do this on the client-side. You may open a feature request nonetheless.
BTW. In AQL, UPDATE doc WITH {} OPTIONS { keepNull: false } will not remove any attributes with a null value! It only removes attributes you set explicitly to null in the WITH {} part. This may apply to the driver as well.
I'm using Algolia's rangeslider from instantsearch.js with tooltips set to false. When the slider's maximum value is displayed (the value to the right side of the slider) (e.g: 2,000), I want it to display as (e.g: 2,000+) (with a "+").
I've tried accessing/resetting the value with jquery like this:
var $sliderMax = $('#my_slider_identifier .ais-range-slider--value').last();
And I've succeeded in getting a handle on the variable, but when I try resetting the maximum value from a custom widget's render() function (so it updates with each new set of results coming in) with the equivalent of $sliderMax.text('2,000' + '+'), nothing happens - I assume because the DOM is being re-written after my call..
If the rangeSlider is showing the maximum value (e.g: 2000), Is there a recommended way to put a '+' on the end?
EDIT:
To give more background: Though I have a range of values from 0-10,000+, the vast majority of the data is in the 0-2000 range, and I thus, truncated my data so that if it's >2000, it shows as 2000.
Also, incidentally and oddly, As a hack, I found that I can write to the DOM if I use a setTimeout of 0 ms (yes, there are stackoverflows on this) and re-do a JQuery selection:
setTimeout(function(){
$('#index_price_eur_day_i .ais-range-slider--value').last()
.text(MAX_PRICE_SLIDER + '+');}, 0);
I'd love to find a more-efficient solution.
I heard from Tim Carry of Algolia and he suggested that I try the :after pseudo element of CSS to fix this.
Indeed, I added this CSS and it always adds a + -- unfortunately even when the slider is not at the max value :/
#my_slider_identifier .ais-range-slider--value:last-of-type::after {
content: "+";
}
So it's not a perfect solution, but it may be "good-enough" - and it's not as ugly/inefficient as using jquery. If anyone has a better solution, please post it!
if addr.types[0] is "country"
console.log addr.long_name.trim().toUpperCase()
$("#user_country_id").each ->
console.log $(this).text().trim() if $(this).text().trim().toUpperCase() is addr.long_name.trim().toUpperCase()
$(this).attr "selected", "selected" if $(this).text().trim().toUpperCase() is addr.long_name.trim().toUpperCase()
return
The code goes through a Google Places object and checks if the address component is "country", then what I want to do is update the Country select box if the TEXT matches what's returned by Google.
It's not working - just console logging the addr.long_name works and just logging the $(this).text() works (I get the whole list of countries of course...) and as far as I can tell they match.
This is the current state of the code. I've clearly tried trim() and toUpperCase() thinking perhaps there is some sort of mismatch there - but nothing has changed.
This is written in CoffeeScript, we're just accessing some of our elements with our typical jQuery accessors.
Any idea what I'm doing wrong?
I believe you want to use .prop instead of .attr. For instance, selected is a property of a select box, not an attribute. So it is semantically correct, and behaves better as well.
I have a listview that has a nested listview which contain radcomboboxes in the itemtemplate. As such, the IDs (as far as I know) are useless to me.
For example, if I have 30 items, each one of those items is going to generate a new combobox so the names are going to be generated by asp. What I need is to be able to grab the selected value from whichever combobox is being worked by the user. I'm currently using jQuery and some absurd parent().parent().children() type nonsense in order to find the correct combobox in relation to the submit button.
When submit button is clicked, I need it to find the selected value of the it's respective combobox so that I can send that to the post submission handler. The problem is that the .val() jQuery method is not working. When I use that with something like:
$(this).parent().parent().children().children(".statusCbo").val();
I end up getting the text value, not the selected value. I triple checked to make sure that I had the fields bound correctly in the aspx file;
DataTextField = '<%#Eval("name") %>' DataValueField = '<%#Eval("id") %>'
But as I said, I'm ending up with the DataTextField value of the selected item. The best explanation I could get was that it had something to do with how the control is requesting the content (via ajax).
So at any rate, could anyone offer some suggestions on how to accurately get the selected value from the combobox?
UPDATE:
I was able to gain reference to the object through a different means:
$(".submitTag").click(
function () {
var topLevel = $(this).closest(".CommentTopLevel");
var status = topLevel.find(".StatusTag").get_value();
//stub to test value
alert(status);
return false;
});
from here, if use status.val(), it will give me the text instead of the value (same issue as before). The documentation implies that I should use status.get_value(); but this is blowing up saying that the method is not supported from the object. Any ideas?
UPDATE:
nevermind, I found that it is a jquery object being returned, so the method isn't included. Continuing to dig.
SOLUTION:
There was just an extra step i needed to do to use traditional methods. I don't know what it took so long for it to click with me:
$(".submitTag").click(
function(){
var topLevel = $(this).closest(".CommentTopLevelTag"); //gets the parent container
var comboBoxID = topLevel.find(".StatusTag").attr("ID"); //gets the clientID of the jQuery object
var comboBoxRef = $find(comboBoxID); //finds the control by id and brings back a non-jQuery object (useable)
var comboBoxSelectedValue = comboBoxRef.get_value(); //uses the Telerik method to get the selected value
});
Its been a little while since I've dealt with Telerik controls, but what you're doing is bypassing the apis Telerik has made for you to use, and that strikes me as a very bad thing. The next release of Telerik Controls could easily break your code.
Look, it shouldn't be that hard to pass the client id from the listview. There's several methods I'd tackle but I'll let you figure that on your own for now. Once you DO have the ClientID for the control, follow the example on telerik's site:
http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx
Once you have that id do some
var combo = $find(someVarReferencingTheId);
Now you have a reference to the combobox in its clientside form. Now find some function that gets what you want from here:
http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html
...
PROFIT!
EDIT: that first link to demos.telerik.com isn't really even needed, I just showed that because that's what I used to get that line of code (I could never remember if it's $get or $find I needed to use, unless I was doing a lot of Telerik clientside stuff at the time.).
EDIT 2: $get and $find are ASP.NET constructs, not Telerik's.