Skip to content

Commit 5041de1

Browse files
committed
add further instructions & screenshots for placeholder attribute in elmish.md for #44 https://youtu.be/NqwbFsSY9xY
1 parent 354685e commit 5041de1

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

elmish.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,10 @@ Your _quest_ is to turn this **`0`** into a **`1`**.
663663
Given the **`JSDOC`** comment and _test_ above,
664664
take a moment to think of how _you_ would write
665665
the `add_attributes` function to apply a CSS `class` to an element. <br />
666-
Note: we have _seen_ the code _before_ in the `counter` example.
667-
The difference is this time we want it to be "generic";
666+
667+
> **Note 0**: we have "_seen_" the code _before_ in the `counter` example:
668+
>
669+
> The difference is this time we want it to be "generic";
668670
we want to apply a CSS `class` to _any_ DOM node.
669671

670672
If you can, make the test _pass_
@@ -703,7 +705,7 @@ Once you make the test _pass_ you _should_ see the following in your Terminal:
703705

704706
The `<input>` form element (_where we create new Todo List items_)
705707
has a helpful `placeholder` attribute _prompting_ us with a question:
706-
"_What needs to be done?_"
708+
"***What needs to be done?***"
707709

708710
Add the following test to the `test/elmish.test.js` file: <br />
709711

@@ -721,15 +723,22 @@ test('elmish.add_attributes set placeholder on <input> element', function (t) {
721723
});
722724
```
723725

726+
_Run_ the test `node test/elmish.test.js`:
724727

728+
![image](https://user-images.githubusercontent.com/194400/43416801-34e48d2c-9431-11e8-8786-7676f9e3972f.png)
725729

730+
You _know_ "the drill"; write the necessary code
731+
in the `add_attributes` function of `elmish.js`
732+
to add a `placeholder` to an `<input>` element
733+
and make this test _pass_:
726734

727-
Write the necessary code in the `add_attributes` function of `elmish.js`
728-
to make this test _pass_.
735+
![image](https://user-images.githubusercontent.com/194400/43416921-8506baaa-9431-11e8-9585-814e704a694d.png)
729736

730737
If you get "stuck", checkout the _complete_ example:
731738
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
732739

740+
<br />
741+
733742

734743
#### Input `autofocus`
735744

examples/todo-list/elmish.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ function add_attributes (attrlist, node) {
7373
// case 'id':
7474
// node.id = a[1]; // apply element id e.g: <input id="toggle-all">
7575
// break;
76-
// case 'placeholder':
77-
// node.placeholder = a[1]; // add placeholder to <input> element
78-
// break;
76+
case 'placeholder':
77+
node.placeholder = a[1]; // add placeholder to <input> element
78+
break;
7979
// case 'style':
8080
// node.setAttribute("style", a[1]); // <div style="display: block;">
8181
// break;

test/elmish.test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ test('elmish.add_attributes applies HTML class attribute to el', function (t) {
104104
// t.end();
105105
// });
106106
//
107-
// test('elmish.add_attributes set placeholder on <input> element', function (t) {
108-
// const root = document.getElementById(id);
109-
// let input = document.createElement('input');
110-
// input.id = 'new-todo';
111-
// input = elmish.add_attributes(["placeholder=What needs to be done?"], input);
112-
// root.appendChild(input);
113-
// const placeholder = document.getElementById('new-todo')
114-
// .getAttribute("placeholder");
115-
// t.equal(placeholder, "What needs to be done?", "paceholder set on <input>");
116-
// t.end();
117-
// });
107+
test('elmish.add_attributes set placeholder on <input> element', function (t) {
108+
const root = document.getElementById(id);
109+
let input = document.createElement('input');
110+
input.id = 'new-todo';
111+
input = elmish.add_attributes(["placeholder=What needs to be done?"], input);
112+
root.appendChild(input);
113+
const placeholder = document.getElementById('new-todo')
114+
.getAttribute("placeholder");
115+
t.equal(placeholder, "What needs to be done?", "paceholder set on <input>");
116+
t.end();
117+
});
118118
//
119119
// test('elmish.add_attributes set data-id on <li> element', function (t) {
120120
// const root = document.getElementById(id);

0 commit comments

Comments
 (0)