diff --git a/js/app/studs.js b/js/app/studs.js index 5cc4f7b..2fbe19c 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 cff4854..d0216fc 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 0002b50..bf75a09 100644 --- a/tpl/part/comments.tpl +++ b/tpl/part/comments.tpl @@ -13,17 +13,23 @@ {/if}
-
{__('Comments', 'Add a comment to the poll')} +
{__('Comments', 'Add a comment to the poll')|html}
- - + +
- - + +
- +