-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of the select element
Close #304
- Loading branch information
Showing
13 changed files
with
743 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
Hashspace listens to the change event of the select elements in order to synchronize its value with the data referenced through the value or model expression. | ||
The options can also be bound, and changing the options list can impact the select value. | ||
|
||
For example, in the following select, we can add or remove the fourth option. | ||
- If we try to set the data model value to 'four' when the option doesn't exist, the select value and the data model will remain unchanged, | ||
- If we remove the option 'four' when this one is selected, the value will be set automatically to the first one. | ||
|
||
[#output] | ||
|
||
**Note:** | ||
- An invalid value (not existing in its options) can't be set in the data model. | ||
- The options list can be change completely. In this case, a valid select value will be kept, otherwise, the first one will be selected. | ||
|
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,84 @@ | ||
<template selectSample(data)> | ||
<div class="info2">The following select and its options are synchronized:</div> | ||
<div class="section"> | ||
Select with bound value: | ||
<select model="{data.selectedValue}" style="width:100px"> | ||
{foreach item in data.options} | ||
<option value="{item.value}">{item.label}</option> | ||
{/foreach} | ||
</select> | ||
</div> | ||
<div class="section"> | ||
The selected value is <span class="info">{data.selectedValue}</span>, | ||
the selected text is <span class="info">{getSelectedText(data.selectedValue)}</span> | ||
</div> | ||
<div class="info2">You can add or remove options, and select one by changing the data model value:</div> | ||
<div class="section"> | ||
<button onclick="{addOption('four', 'Four')}">Add option 'four'</button> | ||
<button onclick="{selectOption('four')}">Select option 'four'</button> | ||
<button onclick="{removeOption('four')}">Remove option 'four'</button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
var d={ | ||
selectedValue:"two", | ||
options : [ | ||
{ | ||
value: "one", | ||
label: "One" | ||
}, | ||
{ | ||
value: "two", | ||
label: "Two" | ||
}, | ||
{ | ||
value: "three", | ||
label: "Three" | ||
} | ||
] | ||
}; | ||
|
||
// Needed by the playground application. | ||
// Update it, but do not remove it! | ||
module.exports = { | ||
template: selectSample, | ||
data: [d] | ||
}; | ||
|
||
var getSelectedText = function(value) { | ||
var options = d.options; | ||
for(var i = 0; i < options.length; i++) { | ||
var option = options[i]; | ||
if (option.value == value) { | ||
return option.label; | ||
} | ||
} | ||
return "no selection"; | ||
} | ||
var addOption = function(value, label) { | ||
var options = d.options; | ||
for(var i = 0; i < options.length; i++) { | ||
var option = options[i]; | ||
if (option.value == value) { | ||
return; | ||
} | ||
} | ||
options.push({value: value, label: label}); | ||
}; | ||
|
||
var selectOption = function(value) { | ||
d.selectedValue = value; | ||
}; | ||
|
||
var removeOption = function(value) { | ||
var options = d.options; | ||
for(var i = 0; i < options.length; i++) { | ||
var option = options[i]; | ||
if (option.value == value) { | ||
options.splice(i, 1); | ||
return; | ||
} | ||
} | ||
}; | ||
</script> |
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,19 @@ | ||
var hashTester = require('hsp/utils/hashtester'); | ||
var sample = require('./selectsample.hsp'); | ||
|
||
describe('"Select" sample', function () { | ||
|
||
var h; | ||
beforeEach(function () { | ||
h = hashTester.newTestContext(); | ||
sample.template.apply(this, sample.data).render(h.container); | ||
}); | ||
|
||
afterEach(function () { | ||
h.$dispose(); | ||
}); | ||
|
||
it('should render "Select"', function () { | ||
|
||
}); | ||
}); |
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
Oops, something went wrong.