-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
bind:group for checkbox inputs
- Loading branch information
Showing
11 changed files
with
186 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/generators/dom/visitors/attributes/binding/getStaticAttributeValue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function getStaticAttributeValue ( node, name ) { | ||
const attribute = node.attributes.find( attr => attr.name.toLowerCase() === name ); | ||
if ( !attribute ) return null; | ||
|
||
if ( attribute.value.length !== 1 || attribute.value[0].type !== 'Text' ) { | ||
// TODO catch this in validation phase, give a more useful error (with location etc) | ||
throw new Error( `'${name} must be a static attribute` ); | ||
} | ||
|
||
return attribute.value[0].data; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/generator/samples/binding-input-checkbox-group/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const values = [ | ||
{ name: 'Alpha' }, | ||
{ name: 'Beta' }, | ||
{ name: 'Gamma' } | ||
]; | ||
|
||
export default { | ||
data: { | ||
values, | ||
selected: [ values[1] ] | ||
}, | ||
|
||
'skip-ssr': true, // values are rendered as [object Object] | ||
|
||
html: ` | ||
<label> | ||
<input type="checkbox"> Alpha | ||
</label> | ||
<label> | ||
<input type="checkbox"> Beta | ||
</label> | ||
<label> | ||
<input type="checkbox"> Gamma | ||
</label> | ||
<p>Beta</p>`, | ||
|
||
test ( assert, component, target, window ) { | ||
const inputs = target.querySelectorAll( 'input' ); | ||
assert.equal( inputs[0].checked, false ); | ||
assert.equal( inputs[1].checked, true ); | ||
assert.equal( inputs[2].checked, false ); | ||
|
||
const event = new window.Event( 'change' ); | ||
|
||
inputs[0].checked = true; | ||
inputs[0].dispatchEvent( event ); | ||
|
||
assert.htmlEqual( target.innerHTML, ` | ||
<label> | ||
<input type="checkbox"> Alpha | ||
</label> | ||
<label> | ||
<input type="checkbox"> Beta | ||
</label> | ||
<label> | ||
<input type="checkbox"> Gamma | ||
</label> | ||
<p>Alpha, Beta</p> | ||
` ); | ||
|
||
component.set({ selected: [ values[1], values[2] ] }); | ||
assert.equal( inputs[0].checked, false ); | ||
assert.equal( inputs[1].checked, true ); | ||
assert.equal( inputs[2].checked, true ); | ||
|
||
assert.htmlEqual( target.innerHTML, ` | ||
<label> | ||
<input type="checkbox"> Alpha | ||
</label> | ||
<label> | ||
<input type="checkbox"> Beta | ||
</label> | ||
<label> | ||
<input type="checkbox"> Gamma | ||
</label> | ||
<p>Beta, Gamma</p> | ||
` ); | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/generator/samples/binding-input-checkbox-group/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{#each values as value}} | ||
<label> | ||
<input type="checkbox" value="{{value}}" bind:group='selected' /> {{value.name}} | ||
</label> | ||
{{/each}} | ||
|
||
<p>{{selected.map( function ( value ) { return value.name; }).join( ', ' ) }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters