Skip to content

Commit

Permalink
Form making value better.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hiscock committed Feb 12, 2014
1 parent 0c2eaa3 commit 71c9d6e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
4 changes: 2 additions & 2 deletions forms/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
serialise: require('./serialise')
serialize: require('./serialise')
value: require('value')
, serialize: require('./serialise')
, value: require('./value')
}
2 changes: 1 addition & 1 deletion forms/serialise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function seraliseForm() {
module.exports = function seraliseForm(el) {

}
2 changes: 1 addition & 1 deletion forms/value/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function getValue(el) {

return el.value
}
6 changes: 4 additions & 2 deletions forms/value/set.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = function setValue(el) {

module.exports = function setValue(el, val) {
if (val === null) val = ''
el.value = val
return el
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "browser-tools",
"version": "0.0.0",
"description": "A modular set of browser tools. DOM manipulation, AJAX, DOM traversal.",
"description": "A modular set of browser tools. DOM manipulation, DOM traversal, Events, CSS, etc.",
"main": "index.js",
"scripts": {
"test": "npm run test-bundle; npm run test-serve; npm run test-open",
Expand Down
28 changes: 26 additions & 2 deletions tests/forms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,46 @@
</head>
<body>

<input type="checkbox" id="input-checkbox">

<!-- Empty initially -->
<input type="text" id="input-text">
<input type="hidden" id="input-hidden">
<input type="password" id="input-password">
<input type="checkbox" id="input-checkbox">
<input type="radio" id="input-radio">
<textarea id="textarea"></textarea>

<!-- Full initially -->
<input type="text" id="input-text-valued" value="foo">
<input type="hidden" id="input-hidden-valued" value="foo">
<input type="password" id="input-password-valued" value="foo">
<input type="checkbox" id="input-checkbox-valued" value="foo">
<input type="radio" id="input-radio-valued" value="foo">
<textarea id="textarea-valued">foo</textarea>

<!-- Select Boxes -->
<select id="select">
<option>Foo</option>
</select>
<select id="select-empty"></select>
<select id="select-valued">
<option value="bar">Foo</option>
</select>
<select id="select-multi" multiple>
<option>Foo</option>
<option>Bar</option>
</select>
<select id="select-multi-level">
<optgroup label="Quux">
<option>Foo</option>
<option>Bar</option>
</optgroup>
<optgroup label="Quuc">
<option>Baz</option>
</optgroup>
</select>

<!-- Tests -->
<script src="bundle.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</body>
</html>
15 changes: 12 additions & 3 deletions tests/forms/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
window.bt = require('../../index')

var test = require('tape')
, get = require('../../forms/value/get')
, set = require('../../forms/value/set')
, els = {
text: document.getElementById('input-text')
, hidden: document.getElementById('input-hidden')
, password: document.getElementById('input-password')
, checkbox: document.getElementById('input-checkbox')
, radio: document.getElementById('input-radio')
, textarea: document.getElementById('textarea')
}
, valuedEls = {
text: document.getElementById('input-text-valued')
, hidden: document.getElementById('input-hidden-valued')
, password: document.getElementById('input-password-valued')
, checkbox: document.getElementById('input-checkbox-valued')
, radio: document.getElementById('input-radio-valued')
, textarea: document.getElementById('textarea-valued')
}

console.log(valuedEls)

test('Initially with no values', function(t) {
for(var k in els) {
var el = els[k]
t.equal(get(el), '', k + ' is an empty string')
if (k === 'checkbox' || k === 'radio') {
t.equal(get(el), 'on', k + ' is on')
}
else {
t.equal(get(el), '', k + ' is an empty string')
}
}

t.end()
Expand Down

0 comments on commit 71c9d6e

Please sign in to comment.