-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Materialize + Framework not updating select value #2838
Comments
I have the same issue with AngularJS. |
I have the same problem with Angular 2 |
I don't know Vue.js enough but with Aurelia I had to issue a custom event on the jQuery This seems to work: new Vue({
el: 'body',
ready: function() {
var suspend = false;
$('#materialize-select').material_select();
$('#materialize-select').on('change', function() {
if (!suspend) {
suspend = true;
var event = new CustomEvent('change', {
detail: 'change',
bubbles: true
});
$(this).get(0).dispatchEvent(event);
}
});
}
}) But only once in this example since the custom Updated fiddle: http://jsfiddle.net/jk5800wh/ |
Yes, with Angular I had to do a manual binding. When change the model, I execute a JQuery function to update de select component. |
Well, I guess you could encapsulate that behaviour in a component easily with either Angular, Angular2 or Vue.js 😄 |
Can you give the exact code you used @ferchoman09? |
of course @MichaelDeBoey This is my select component:
I use a custom directive:
And in the controller I am watching the variable that I have in the ng-model of select component:
So, I am simulating the two ways binding.
Not the best, but I had to do so. |
Oh you're still using Angular.js, not Angular 2 @ferchoman09? |
@MichaelDeBoey |
No problem @ferchoman09 😄 |
Yes, I hope too that materializecss team improve the select implementation for compatibility with frameworks. |
Every two-way binding framework seems to be affected. There are surely ways to get around this problem, I use a custom directive myself – but yeah, we are waiting for some improvements on this one. |
I have the same problem with Angular 2, any solution for this problem? |
My problem is little bit different:
http://jsfiddle.net/tceydeliler/9j8zzfn6 I think Its called as DOM manupulation. |
For change the materializecss select I had to do that:
|
Where do I use "#idselect" ? |
It works. |
@ferchoman09 thanks for the workaround. shame on you authors. |
In angular2 you can use it: For get: $('select').material_select();
$('select').change((e) => {
this.model[e.currentTarget.name] = e.currentTarget.value;
}); For set: this.model.gender = 'male'; // or this.model = newValues;
$('select').material_select(); |
@Thanood is on right track just add else. new Vue({
el: 'body',
ready: function() {
var suspend = false;
$('#materialize-select').material_select();
$('#materialize-select').on('change', function() {
if (!suspend) {
suspend = true;
var event = new CustomEvent('change', {
detail: 'change',
bubbles: true
});
$(this).get(0).dispatchEvent(event);
} else {
suspend = false;
}
});
}
}) http://jsfiddle.net/GreyZact/qukwodpv/ It even works if there are multiple select objects. |
Any solution who works with template driven and reactive form in Angular 2? |
@ferchoman09 @virtualvoid Can you guys tell me more about the solution for vue2?thanks! |
Anybody knows if there's any solution for this using reactive forms in Angular2? |
You can use https://github.com/sherweb/ng2-materialize. We did a wrap for the select that work on both template driven and reactive forms. |
Hi guys, i solved using @GreyZact snippet, but i use *.vue templates. And created more productive solution: let selectGambiCounter = 0;
export default class MyHelper {
constructor() {
throw new Error('Esta classe nao pode ser instanciada');
}
static gambiSelects () {
selectGambiCounter = 0;
$('.material-gambi').off('change');
$('.material-gambi').on('change', function() {
selectGambiCounter ++;
if (selectGambiCounter == 1) {
let event = new CustomEvent('change', {
detail: 'change',
bubbles: true
});
$(this).get(0).dispatchEvent(event);
console.log(`trigger ${selectGambiCounter}`);
} else if (selectGambiCounter >= 2) {
selectGambiCounter = 0;
}
});
}
} In template file I added class material-gambi on my selects and in JS code:
Works lazy, but works |
Any updates on this, please? |
I wish this were fixed. I can't use my forms the way I want to because of this. |
Will look into a solution for this
On Wed, Aug 2, 2017 at 8:20 AM Craig ***@***.***> wrote:
I wish this were fixed. I can't use my forms the way I want to because of
this.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2838 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACpax5nCa1PeVCjuMzEPJ5xBSPmEVE6mks5sUJOwgaJpZM4HiFWN>
.
--
Doggy sends his greetings from Mars.
|
in vuejs + axios ajax call is promises logic.
|
Hi, for this issue specific for Vue.JS I created a component that contains a select and handle the add, update options with jQuery, and every time the user changes the selected value it emits the change with the new selected value. Hope it help some people. To not copy the entire code here, I link it. Code: MaterialSelect.vue |
The issue seems to be related to jQuery's trigger('change') event not being caught by Angular. Possible fix is to trigger a change event this way, which seems to fire Angular's own handlers properly. Haven't testing this with other frameworks yet. var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
element.dispatchEvent(evt); |
Hi, please excuse my english. I found this solution for Angular 2 HTML
And in the .ts file i have
@MichaelDeBoey @scote @MelanyB maybe it will help you guys |
Thank you @ferchoman09 for the tips! |
Its working for me but its temporary hack *.component.html
*.component.ts
|
@ferchoman09 (thanks) gave me a clue to update options in a Materialize Select ... If you need load new options in a Materialize Select:
|
The possible solution that I found is to use an input, and attach it to a dropdown content. It works well with vue even when you are dynamically creating dropdown. And its reactive, that you don't have to emit any other event to bind values. Codepen: https://codepen.io/aaha/project/editor/DGJNLE
|
Problem is fixed for me after updating VueJS to 1.0.0-beta. |
Hello, I've read @nihattunali 's solution and it worked for me. I'm using async mounted(){
this.$store.commit("activarEspera");
try{
let respuesta = await this.$http.post("/api/v1.0/escuelas", {
sigla: "IPN"
});
respuesta.body.escuelas.forEach(escuela => this.escuelas.push(escuela));
//These two awaits are important. Both are necessary
await M.updateTextFields();
await M.FormSelect.init(document.querySelectorAll("select"));
}
catch(respuesta){
M.toast({
html: respuesta.body,
displayLength: 1500
});
}
this.$store.commit("desactivarEspera");
} Tested on VueJS 2.5.13 and Materialize 1.0.0-rc.2. |
For those who still having problems using HTML <select ng-model="newArticle.group" id="group">
<option ng-repeat="group in groups" value="{{group._id}}"
ng-selected="group.selected == true">{{group.name}}
</option>
</select> CONTROLLER JS function getGroups() {
$http.get("/api/v1/groups")
.then(function (response) {
console.log('Groups retrieved');
$scope.groups.push(...response.data);
setTimeout(function () {
$('#group').find('option[value="0"]').prop('selected', true);
$('#group').formSelect();
}, 2000);
}, function (error) {
console.log('Error retrieving groups', error);
alert("Ups! Ha ocurrido un error al recuperar los grupos, inténtalo de nuevo en unos minutos.");
});
} Hope it helps! :-) |
It works for me. What's the drawback about use await inside mounted? |
in angular 9: i just added a hack below code in ngAfterViewInit() reason is select initialized before it actually process all options |
Model value is not updated when
material_select()
is applied to the<select>
.I've made a fiddle to show you what's going on:
http://jsfiddle.net/maxflex/j8xcm7d2/
There are also other people facing the same problem: one, two
The text was updated successfully, but these errors were encountered: