Skip to content
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

Radio box not updating properly #60

Closed
adekoyejoakinhanmi opened this issue May 30, 2017 · 4 comments
Closed

Radio box not updating properly #60

adekoyejoakinhanmi opened this issue May 30, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@adekoyejoakinhanmi
Copy link
Contributor

adekoyejoakinhanmi commented May 30, 2017

Hi @kingpixil, Radio boxes with the same m-model value do update data model. Check this out:

new Moon({
el : "#app",
data : {
	names : ['joe', 'peter', 'john', 'maxwell', 'jones'],
        person : 'joe'
}
});

And the html:

<div id="app">
<label m-for="personName in names" >
  <input type="radio" m-model="person" name="person" m-literal:value="personName" m-literal:id="personName" />        {{personName}}
</label>

<br/>

  {{person}}
</div>

The radiobox doesn't change the value of {{person}} as expected. Or is there something I am missing?

@kbrsh
Copy link
Owner

kbrsh commented May 30, 2017

Hey,

First of all, m-model is passing by value, meaning that you need to use it to refer to an index of an array, not the value of the item in the array. So you would change the value to m-model="names[index]", and the value of the m-for to "personName,index in names".

I'll be fixing m-model to work with radio buttons better in v0.11.0, by keeping a reference to the compiled value of regular attributes and m-literal.

@kbrsh kbrsh self-assigned this May 30, 2017
@kbrsh kbrsh added the bug label May 30, 2017
@kbrsh kbrsh added this to the v0.11.0 milestone May 30, 2017
@adekoyejoakinhanmi
Copy link
Contributor Author

Okay, if this is the case. How then will I reference it in the view? i.e. how will I set the value of {{person}}

@kbrsh
Copy link
Owner

kbrsh commented May 30, 2017

You can pass {{person}} to a method using m-on and it should pass by reference, but passing it through m-model would require Moon to detect this and compile it as Javascript (adding a lot of weight).

@kbrsh kbrsh closed this as completed in 11ff0de Jul 10, 2017
@kbrsh
Copy link
Owner

kbrsh commented Jul 10, 2017

Alright! Sorry for the late fix, but the example you gave is now working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants