Skip to content

Conversation

fergaldoyle
Copy link
Contributor

Radio input
Added the ability to specify an expression, via attribute exp, which will be evaluated on the current scope and set as the v-model value when the radio is selected, similar to Angular ng-value. e.g.

<input type="radio" name="sample" v-model="model.radio" value="1" exp="true" />
<input type="radio" name="sample" v-model="model.radio" value="0" exp="false" />

If the first radio is selected, model.radio === true instead of "1". When the model updates and exp is present, we match the evaluated expression rather than the value string when choosing which radio to set as checked.

Checkbox input
Added the ability to specify a true-value and false-value which will override the default true/false values. Similar to Angular ng-true-value and ng-false-value. e.g:

<input type="checkbox" v-model="model.checkbox1" true-value="'someTrueValue'" false-value="'someFalseValue'"/>
<input type="checkbox" v-model="model.checkbox2" true-value="expression1" false-value="expression2"/>

If present true-value and false-value will be evaluated on the current scope, and set as the v-model value when the checkbox changes. Similar to the radio, if the model changes a comparison is made against true-value and false-value values to determine the checkbox state.

this._getValue = getValue

function matchValue (value) {
var trueValue = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since el.checked can be only true or false, we just need to check if value equals trueValue here - in all other cases we just return false. This could make matchValue much simpler.

@fergaldoyle
Copy link
Contributor Author

Yes makes sense to use true-exp and false-exp. Also simplified matchValue, either true/trueExp matches the incoming value or it does not, which implies a false match.

yyx990803/vue@b8e364f

@yyx990803
Copy link
Member

Cool! Mind rebasing against latest dev so the CI build can pass?

@fergaldoyle
Copy link
Contributor Author

Hitting the limits of my git knowledge here, I've re-based v-model-enhancments onto dev, will I have to open a new pull request?

https://github.com/fergaldoyle/vue/commits/dev

@yyx990803
Copy link
Member

Here's what you should probably do:

git checkout dev
git pull https://github.com/yyx990803/vue.git dev
git checkout v-model-enchancements
git rebase dev
git push -f

@fergaldoyle
Copy link
Contributor Author

That seemed to work

yyx990803 added a commit that referenced this pull request Aug 12, 2015
v-model radio and checkbox expressions
@yyx990803 yyx990803 merged commit 1e15840 into vuejs:dev Aug 12, 2015
@yyx990803
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants