Skip to content

Commit

Permalink
Merge pull request #25 from SriDodda/master
Browse files Browse the repository at this point in the history
Srini - Beacon add attachment client side validation
  • Loading branch information
rajatguptarg committed Dec 29, 2015
2 parents 1e7cc36 + 4367b7d commit eae6c21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
31 changes: 31 additions & 0 deletions beacons/static/js/attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function attachment(){
$(document).ready(function(){
attachment.init();
});

attachment.init = function(){
attachment.form = $("form")[0];
attachment.description = $("#description")[0];

attachment.form.onsubmit = attachment.validateAndSubmit;
}

attachment.validateAndSubmit = function(e){
if(!isValidAttachment()){
e.preventDefault();
}
}

function isValidAttachment(){
var description = attachment.description.value;
if(description.length != 0){
try{
JSON.parse(description);
return true;
}catch(e){
return false;
}
}
return false;
}
})();
21 changes: 8 additions & 13 deletions beacons/templates/attachment.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends "base.jinja" %}

{% block script %}
<script type="text/javascript" src="../static/js/attachment.js"></script>
{% endblock %}

{% block title %}
Attach
{% endblock %}
Expand All @@ -18,7 +22,7 @@
<div class="form-group">
<label class="control-label col-xs-3" for="name">NameSpace:</label>
<div class="col-xs-7">
<input type="text" class="form-control" name="namespace" value={{beacon}}>
<input type="text" readonly class="form-control" name="namespace" value={{beacon}}>
</div>
</div>

Expand All @@ -27,19 +31,14 @@
<div class="form-group">
<label class="control-label col-xs-3" for="name">Beacon Name:</label>
<div class="col-xs-7">
<input type="text" class="form-control" name="name" value={{ name }}>
<input type="text" readonly class="form-control" name="name" value={{ name }}>
</div>
</div>

<br>
{% for message in get_flashed_messages() %}
<div class="flash" style="color: red">{{ message }}</div>
{% endfor %}

<div class="form-group">
<label class="control-label col-xs-3" for="name">Message:</label>
<div class="col-xs-7">
<textarea rows=5 cols=40 class="form-control" name="msg" placeholder="Enter Message to attach"></textarea>
<textarea id="description" rows=5 cols=40 class="form-control" name="msg" placeholder="Enter Message to attach"></textarea>
</div>
</div>

Expand All @@ -48,16 +47,12 @@

<div class="form-group">
<div class="col-xs-offset-4 col-xs-8">
<input type="submit" onclick="myFunction()" class="btn btn-success" value="Submit">
<input type="submit" class="btn btn-success" value="Submit">
<input type="reset" class="btn btn-danger" value="Reset">
</div>
</div>
</form>
</div>
<div class="col-md-4"></div></div>
</div>
<script>
function myFunction() {
alert("hello")
</script>
{% endblock %}

0 comments on commit eae6c21

Please sign in to comment.