I want to get multiselect values from rallyfieldvaluecombobox. We can declare rallyfieldvaluecombobox to be multiselect with multiSelect: true but I am not sure how to read/get selected values.
You should be able to use it just like any other combobox.
Get selected values:
combo.getValue(); // ['Value1', 'Value2', 'Value3']
Set selected values:
combo.setValue(['Value1', 'Value2']);
I agree with you, the docs are probably not super clear on how to deal with multi-value.
Related
I've created a small jsfiddle which explains the error and how to reproduce it here: https://jsfiddle.net/4Leu9a6x/57/
I have a select on which I use #change and :value to update and show the value. I know I could use v-model but my app is rather complex so this is the only way to do it currently.
The problems appears when I change the options dynamically. As soon as I change them the value of the select (the one the user sees) is not the same as the real value (saved in data by vue). Even though I do have :value.
I don't understand why it doesn't show a gray select (with nothing selected) when :value is not inside the options.
The jsfiddle above will clearly show this problem. Any ideas on how to keep the two in sync?
v-model has specific behavior to deal with the situation when a <select>'s options are changed dynamically. Since you're not using v-model, you'll have to deal with these issues yourself.
Like other input elements, a <select> has its own internal state (value and selectedIndex) that the browser maintains (not Vue). If you change the options without changing the value, then when Vue re-renders it won't set the value of the select since the value didn't change, so you're left with whatever state the browser chooses, and potentially the bound value will be out of sync with the actual value of the select.
A couple of solutions:
Bind key of the <select> to recreate the element when the options change (fiddle).
Wrap the <select> in a component and manually set the selectedIndex of the element to the index of the selected option. Read the v-model source to see how Vue does it.
When you change the options data, also change the value data so that it corresponds to an actual option. But this doesn't solve the problem of having the <select> select no option when the value doesn't match any option after changing the options but not the value.
Add this.val = this.options[0]; while running shuffle method. This is because each time the shuffle method runs it resets the options, since your value is not two way bound, the value is not being updated.
Else you can refractor your code and use v-model.
new Vue({
el: "#app",
data: {
val: 2,
options: [1, 2, 3, 4]
},
methods: {
shuffle() {
this.options = [Math.random(), Math.random(), Math.random()]
this.val = this.options[0];
}
}
})
I am trying make a conditional select-box. There are 2 select-boxes. When select-box1 1's value changes then the 2nd select-box value automatically need to get selected to a value and it will also be disabled.
So far , i am able to do the conditional select where select-box 1's option changes value in select-box2 but it shows error in vue.
Error is--
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "value"
Also , i can disable the 2nd select-box but when i use dynamic disabled the value doesn't get set.
Question in brief:
1st selectbox has value-- a)one time payment & b)subscription and
2nd selectbox has value--a)held & b) Immediate.
Now, if 1st selectbox's subscription is selected then in the 2nd selectbox, it should be set to immediate and also get disabled.
Below is the Code Sandbox link--
https://codesandbox.io/s/conditional-select-forked-h61po?file=/src/components/HelloWorld.vue
If there is a better way of achieving this, then feel free to share ...
You don't need a ref, you can change the value of selected2 directly because it's not a prop, but a data field. Remove the reference in your component, like so:
<b-form-select
v-model="selected2"
:options="options2"
:disabled="isDisabled"
></b-form-select>
and change your onChange method to this (you don't need the else block as well):
onChange(event) {
if (event === "subscription") {
this.selected2 = "Immediate";
this.isDisabled = true;
}
},
Try it. I've tested it and it works.
I think the best way is to watch the 2-way-binding (selected) with a watcher.
See: https://v3.vuejs.org/guide/reactivity-computed-watchers.html#watch
And if the value changes you can check if the new value is 'subscription'.
And to select the wante option in the 2nd select you just have to asign the wanted value to the 2-way-binding (selected2). And for disabling set isDisabled to true.
i am using dropdown widget in dojo (dijit), i want to set the selected option the top menu
i tried this code:
dijit.byId('projectId').addOption({ label: item.projname , value: item.projid, selected:true });
here the selected: true
is not working
Thanks
The asker's code is not correct as the selected property applies for the construction of the object. As PaulR suggested, the asker should use dijit.byId('projectId').set("value",item.projid); when the select widget has already been created.
Aside: I would suggest using the AMD module "dijit/registry" rather than the root dijit object.
According to the documentation, "selected: true" is the correct way to specify the selected item. See https://dojotoolkit.org/reference-guide/1.9/dijit/form/Select.html.
I noticed the same issue in the past, and noticed that this only works correctly when an option has a value. So, can you check if "item.projid" contains a value?
Take a look at this example. Here you can see multiselect field that allows user to select multiple rows by pressing CTRL key down.
I have tried to use the keyUp function to capture the CTRL key, in order to somehow prevent user from selecting more than 1 row. But I am not sure hot to do this with mulitiselect xtype.
You might think way would I want a single select instead of multiselect, it is just something I need for my app I am working on. I like the layout of the example and want to keep the structure the same. The only thing I want to change is from multi -> single.
Thanks for any help.
The following config needs to go in your multiselect config. This will set the config for the boundList which is where the multiselect is.
listConfig: {
multiSelect: false
}
I created a form with nested container, fieldset and there a few checkbox on the form too.
as far as the form.getValues() can do it extract all values except the checkboxes so I want to extract the fields value manually. However the code sample I found so far
var values = {};
form.items.each( function(f) {
values[f.getName()] = f.getValue();
});
not work because the loop can get only the container, fieldset etc but not the actual field (textfield, combo etc). Could someone show me how to proper recursively extract all the field value?
Thanks.
It's because checkboxes dont hava a getSubmitData() which getValues() uses.
Try yourForm.getFieldValues() instead.
In ExtJs 4.0 you can use:
var fieldValues = Ext.getCmp('yourForm').form.getFieldValues();