Skip to content
Snippets Groups Projects
Commit b66a47ef authored by Antonin's avatar Antonin
Browse files

Added simple javascript check for the name.

	- The goal here is to prevent the losing of the choices by having a bad name.
	- This is a POC, there is probably some cleaning before merge
parent 3044de5a
No related branches found
No related tags found
No related merge requests found
...@@ -373,5 +373,7 @@ $smarty->assign('comments', $comments); ...@@ -373,5 +373,7 @@ $smarty->assign('comments', $comments);
$smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('editingVoteId', $editingVoteId);
$smarty->assign('message', $message); $smarty->assign('message', $message);
$smarty->assign('admin', true); $smarty->assign('admin', true);
$smarty->assign('parameter_name_regex', NAME_REGEX);
$smarty->assign('parameter_name_error', _('Name is incorrect.'));
$smarty->display('studs.tpl'); $smarty->display('studs.tpl');
\ No newline at end of file
$(document).ready(function() {
$("#poll_form").submit(function( event ) {
var name = $("#name").val();
var regexContent = $("#parameter_name_regex").text().split("/");
var regex = new RegExp(regexContent[1], regexContent[2]);
if (name.length == 0 || !regex.test(name)) {
event.preventDefault();
var errorMessage = $("#parameter_name_error").text();
var addedDiv = "<div class='alert alert-dismissible alert-danger' role='alert'>";
addedDiv += errorMessage;
addedDiv += "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
$("#message-container").empty();
$("#message-container").append(addedDiv);
$('html, body').animate({
scrollTop: $("#message-container").offset().top
}, 750);
}
});
});
\ No newline at end of file
...@@ -202,5 +202,7 @@ $smarty->assign('comments', $comments); ...@@ -202,5 +202,7 @@ $smarty->assign('comments', $comments);
$smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('editingVoteId', $editingVoteId);
$smarty->assign('message', $message); $smarty->assign('message', $message);
$smarty->assign('admin', false); $smarty->assign('admin', false);
$smarty->assign('parameter_name_regex', NAME_REGEX);
$smarty->assign('parameter_name_error', _('Name is incorrect.'));
$smarty->display('studs.tpl'); $smarty->display('studs.tpl');
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
<script src="{'nav/nav.js'|resource}" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav --> <script src="{'nav/nav.js'|resource}" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav -->
{/if} {/if}
{block name="header"}{/block}
</head> </head>
<body> <body>
<div class="container ombre"> <div class="container ombre">
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<h3>{__('Poll results\\Votes of the poll')}</h3> <h3>{__('Poll results\\Votes of the poll')}</h3>
<div id="tableContainer" class="tableContainer"> <div id="tableContainer" class="tableContainer">
<form action="" method="POST"> <form action="" method="POST" id="poll_form">
<table class="results"> <table class="results">
<caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption> <caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption>
<thead> <thead>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<h3>{__('Poll results\\Votes of the poll')}</h3> <h3>{__('Poll results\\Votes of the poll')}</h3>
<div id="tableContainer" class="tableContainer"> <div id="tableContainer" class="tableContainer">
<form action="" method="POST"> <form action="" method="POST" id="poll_form">
<table class="results"> <table class="results">
<caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption> <caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption>
<thead> <thead>
......
{extends file='page.tpl'} {extends file='page.tpl'}
{block name="header"}
<script src="{"js/app/studs.js"|resource}" type="text/javascript"></script>
{/block}
{block name=main} {block name=main}
{if !empty($message)} <div id="message-container">
<div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div> {if !empty($message)}
{/if} <div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>
{/if}
</div>
{* Global informations about the current poll *} {* Global informations about the current poll *}
...@@ -37,6 +43,12 @@ ...@@ -37,6 +43,12 @@
</div> </div>
</div> </div>
<div class="hidden">
<p id="parameter_name_regex">{$parameter_name_regex}</p>
<p id="parameter_name_error">{$parameter_name_error}</p>
</div>
{* Vote table *} {* Vote table *}
{if $poll->format === 'D'} {if $poll->format === 'D'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment