Skip to content

Instantly share code, notes, and snippets.

@mattiaslundberg
Last active August 29, 2015 14:01
Show Gist options
  • Save mattiaslundberg/b116a20aabd9be569372 to your computer and use it in GitHub Desktop.
Save mattiaslundberg/b116a20aabd9be569372 to your computer and use it in GitHub Desktop.
Update the regExp of a dojo validation textbox
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test validation</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/claro/claro.css">
</head>
<body class="claro">
<h1 id="headline">Change the text to something without spaces:</h1>
<div id="container"></div>
<button data-dojo-type="dijit/form/Button" id="mybtn" type="button">I want to enter a space...</button>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/dojo.js" data-dojo-config="async: true"></script>
<script type="text/javascript">
require(["dijit/form/ValidationTextBox", "dijit/form/Button"]);
require(["dojo/ready", "dojo/dom", "dojo/on", "dijit/registry", "dojo/parser", "dijit/InlineEditBox"], function(rdy, dom, on, reg, prs, InlineEditBox) {
prs.parse();
eb = new InlineEditBox({
editor: 'dijit.form.ValidationTextBox',
editorParams: {
regExp: '[\\w]+',
},
value: "someTextContent",
style: "width: 90px"
}, "container");
rdy(function() {
on(dom.byId("mybtn"), "click", function() {
dom.byId("headline").innerHTML += " jk, enter some spaces...";
eb.wrapperWidget.editWidget.set("regExp", ".*");
});
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test validation</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/claro/claro.css">
</head>
<body class="claro">
<h1 id="headline">Change the text to something without spaces:</h1>
<input type="text" name="phone" id="phone" value="someTestString" required="true"
data-dojo-type="dijit/form/ValidationTextBox"
data-dojo-props="regExp:'[\\w]+', invalidMessage:'Invalid Non-Space Text.'" />
<button data-dojo-type="dijit/form/Button" id="mybtn" type="button">I want to enter a space...</button>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/dojo.js" data-dojo-config="async: true"></script>
<script type="text/javascript">
require(["dijit/form/ValidationTextBox", "dijit/form/Button"]);
require(["dojo/ready", "dojo/dom", "dojo/on", "dijit/registry", "dojo/parser"], function(rdy, dom, on, reg, prs) {
prs.parse();
rdy(function() {
on(dom.byId("mybtn"), "click", function() {
dom.byId("headline").innerHTML += " jk, enter some spaces...";
reg.byId("phone").set("regExp", ".*");
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment