Skip to content

Commit

Permalink
Replace alert in canvas_api_tutorial (#34629)
Browse files Browse the repository at this point in the history
* Replace alert in canvas_api_tutorial

* Add eventlistener to form element
  • Loading branch information
evelinabe authored Jul 5, 2024
1 parent 188fe7f commit 36d589b
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,8 @@ function draw() {
ctx.lineWidth = 10;

// check input
if (document.getElementById("miterLimit").value.match(/\d+(\.\d+)?/)) {
if (document.getElementById("miterLimit").checkValidity()) {
ctx.miterLimit = parseFloat(document.getElementById("miterLimit").value);
} else {
alert("Value must be a positive number");
}

// Draw lines
Expand All @@ -419,11 +417,9 @@ function draw() {
<td>
Change the <code>miterLimit</code> by entering a new value below and
clicking the redraw button.<br /><br />
<form onsubmit="return draw();">
<label for="miterLimit">Miter limit</label>
<input type="number" size="3" id="miterLimit" />
<input type="submit" value="Redraw" />
</form>
<label for="miterLimit">Miter limit</label>
<input type="number" id="miterLimit" size="3" min="1" />
<input type="submit" id="redraw" value="Redraw" />
</td>
</tr>
</table>
Expand All @@ -434,6 +430,9 @@ document.getElementById("miterLimit").value = document
.getElementById("canvas")
.getContext("2d").miterLimit;
draw();

const redraw = document.getElementById("redraw");
redraw.addEventListener("click", draw);
```

{{EmbedLiveSample("A_demo_of_the_miterLimit_property", "", "180")}}
Expand Down

0 comments on commit 36d589b

Please sign in to comment.