diff --git a/js/app/studs.js b/js/app/studs.js index 5cc4f7b7b904931337bab5039276bcb114595241..2fbe19cc5a93d3e1fe06f721e5f3e0945a153950 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -16,6 +16,9 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ + +var form; + $(document).ready(function () { @@ -108,7 +111,19 @@ $(document).ready(function () { } }); - var form = $('#comment_form'); + + form = $('#comment_form'); + + + checkCommentSending(); + + $("#comment_name").on("keyup change", checkCommentSending); + $("#comment").on("keyup change", checkCommentSending); + + $("#comment_name").on("change", formatValues); + $("#comment").on("change", formatValues); + + form.submit(function(event) { event.preventDefault(); @@ -168,3 +183,31 @@ $(document).ready(function () { } }); }); + + +function formatValues() { + var value = $(this).val().trim(); + + if (0 === value.length) { + $(this).val(""); + } +} + +function checkCommentSending() { + + var button = $("#add_comment"); + + // on page load, "textSend" is not set + if ("undefined" === typeof button.data("textSend")) { + button.data("textSend", button.val()); + } + + + if (!form.get(0).checkValidity()) { + button.prop("disabled", true); + button.val(button.data("textWait")); + } else { + button.prop("disabled", false); + button.val(button.data("textSend")); + } +} diff --git a/locale/en.json b/locale/en.json index cff4854d05cc803b0f67209b5a4bbfd0c3e88587..d0216fcb0da41bca0d7921c22a3fb13617c5de94 100644 --- a/locale/en.json +++ b/locale/en.json @@ -84,6 +84,7 @@ "Remove the comment": "Remove comment", "Send the comment": "Submit comment", "Your comment": "Comment", + "Type your name and a comment to send it" : "Type your name and a comment to send it", "anonyme": "anonymous" }, "Date": { diff --git a/tpl/part/comments.tpl b/tpl/part/comments.tpl index 0002b5056a7862725a830c1973c6476f01dc9691..bf75a098a62b002e1a827aad446a54b9ecc3e515 100644 --- a/tpl/part/comments.tpl +++ b/tpl/part/comments.tpl @@ -13,17 +13,23 @@ {/if} <div class="hidden-print jumbotron"> <div class="col-md-6 col-md-offset-3"> - <fieldset id="add-comment"><legend>{__('Comments', 'Add a comment to the poll')}</legend> + <fieldset id="add-comment"><legend>{__('Comments', 'Add a comment to the poll')|html}</legend> <div class="form-group"> - <label for="comment_name" class="control-label">{__('Generic', 'Your name')}</label> - <input type="text" name="name" id="comment_name" class="form-control" maxlength="60" /> + <label for="comment_name" class="control-label">{__('Generic', 'Your name')|html}</label> + <input type="text" name="name" id="comment_name" class="form-control" maxlength="60" required> </div> <div class="form-group"> - <label for="comment" class="control-label">{__('Comments', 'Your comment')}</label> - <textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea> + <label for="comment" class="control-label">{__('Comments', 'Your comment')|html}</label> + <textarea name="comment" id="comment" class="form-control" rows="2" cols="40" required></textarea> </div> <div class="pull-right"> - <input type="submit" id="add_comment" name="add_comment" value="{__('Comments', 'Send the comment')}" class="btn btn-success"> + <button + type="submit" + id="add_comment" + value="{__('Comments', 'Send the comment')|html}" + class="btn btn-success" + data-text-wait="{__('Comments', 'Type your name and a comment to send it')|html}" + > </div> </fieldset> </div>