1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 04:10:38 +02:00

Issue #539 - validation of user-extended elements will automatically switch tabs when an error is found.

This commit is contained in:
Cameron
2014-10-06 17:32:36 -07:00
parent 877fad903a
commit ad0491c901
4 changed files with 69 additions and 30 deletions

View File

@@ -267,6 +267,8 @@ class usersettings_shortcodes extends e_shortcode
{ {
$sql = e107::getDb(); $sql = e107::getDb();
$tp = e107::getParser(); $tp = e107::getParser();
$frm = e107::getForm();
$qry = " $qry = "
SELECT * FROM #user_extended_struct SELECT * FROM #user_extended_struct
@@ -428,7 +430,7 @@ class usersettings_shortcodes extends e_shortcode
if(defined($fname)) $fname = constant($fname); if(defined($fname)) $fname = constant($fname);
$fname = $tp->toHTML($fname, "", "emotes_off, defs"); $fname = $tp->toHTML($fname, "", "emotes_off, defs");
if($fInfo['user_extended_struct_required'] == 1) if($fInfo['user_extended_struct_required'] == 1 && !deftrue('BOOTSTRAP'))
{ {
$fname = str_replace("{FIELDNAME}", $fname, $REQUIRED_FIELD); $fname = str_replace("{FIELDNAME}", $fname, $REQUIRED_FIELD);
} }

View File

@@ -208,6 +208,11 @@ class e_form
$c = 0; $c = 0;
foreach($array as $key=>$tab) foreach($array as $key=>$tab)
{ {
if(is_numeric($key))
{
$key = 'tab-'.$this->name2id($tab['caption']);
}
$active = ($c == 0) ? ' class="active"' : ''; $active = ($c == 0) ? ' class="active"' : '';
$text .= '<li'.$active.'><a href="#'.$key.'" data-toggle="tab">'.$tab['caption'].'</a></li>'; $text .= '<li'.$active.'><a href="#'.$key.'" data-toggle="tab">'.$tab['caption'].'</a></li>';
$c++; $c++;
@@ -222,6 +227,11 @@ class e_form
$c=0; $c=0;
foreach($array as $key=>$tab) foreach($array as $key=>$tab)
{ {
if(is_numeric($key))
{
$key = 'tab-'.$this->name2id($tab['caption']);
}
$active = ($c == 0) ? ' active' : ''; $active = ($c == 0) ? ' active' : '';
$text .= '<div class="tab-pane'.$active.'" id="'.$key.'">'.$tab['text'].'</div>'; $text .= '<div class="tab-pane'.$active.'" id="'.$key.'">'.$tab['text'].'</div>';
$c++; $c++;

View File

@@ -676,6 +676,7 @@ class e107_user_extended
$regexfail = $tp->toText($parms[2]); $regexfail = $tp->toText($parms[2]);
$fname = "ue[user_".$struct['user_extended_struct_name']."]"; $fname = "ue[user_".$struct['user_extended_struct_name']."]";
$required = vartrue($struct['user_extended_struct_required']) ? "required" : ""; $required = vartrue($struct['user_extended_struct_required']) ? "required" : "";
$fid = $frm->name2id($fname);
if(strpos($include, 'class') === FALSE) if(strpos($include, 'class') === FALSE)
{ {
@@ -687,7 +688,7 @@ class e107_user_extended
{ {
case EUF_TEXT : //textbox case EUF_TEXT : //textbox
case EUF_INTEGER : //integer case EUF_INTEGER : //integer
$ret = "<input name='{$fname}' value='{$curval}' {$include} {$required} />"; $ret = "<input id='{$fid}' name='{$fname}' value='{$curval}' {$include} {$required} />";
return $ret; return $ret;
break; break;
@@ -722,7 +723,7 @@ class e107_user_extended
else else
{ {
$chk = ($curval == $val)? " checked='checked' " : ""; $chk = ($curval == $val)? " checked='checked' " : "";
$ret .= "<input {$include} type='radio' name='{$fname}' value='{$val}' {$chk} {$required} /> {$label}"; $ret .= "<input id='{$fid}' {$include} type='radio' name='{$fname}' value='{$val}' {$chk} {$required} /> {$label}";
} }
} }
@@ -766,7 +767,7 @@ class e107_user_extended
break; break;
case EUF_DROPDOWN : //dropdown case EUF_DROPDOWN : //dropdown
$ret = "<select {$include} name='{$fname}' {$required} >\n"; $ret = "<select {$include} id='{$fid}' name='{$fname}' {$required} >\n";
$ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it. $ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it.
foreach($choices as $choice) foreach($choices as $choice)
{ {
@@ -790,7 +791,7 @@ class e107_user_extended
if (!method_exists($className, 'getValue')) return '???-???'; if (!method_exists($className, 'getValue')) return '???-???';
$temp->pointerReset(); $temp->pointerReset();
$ret = "<select {$include} name='{$fname}' {$required} >\n"; $ret = "<select id='{$fid}' {$include} name='{$fname}' {$required} >\n";
$ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chooses it. $ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chooses it.
while (FALSE !== ($row = $temp->getValue(0, 'next'))) while (FALSE !== ($row = $temp->getValue(0, 'next')))
{ {
@@ -810,7 +811,7 @@ class e107_user_extended
if($sql->db_Select($tp -> toDB($choices[0], true), $tp -> toDB($choices[1], true).",".$tp -> toDB($choices[2], true), "1 $order")){ if($sql->db_Select($tp -> toDB($choices[0], true), $tp -> toDB($choices[1], true).",".$tp -> toDB($choices[2], true), "1 $order")){
$choiceList = $sql->db_getList('ALL',FALSE); $choiceList = $sql->db_getList('ALL',FALSE);
$ret = "<select {$include} name='{$fname}' {$required} >\n"; $ret = "<select id='{$fid}' {$include} name='{$fname}' {$required} >\n";
$ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it. $ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it.
foreach($choiceList as $cArray) foreach($choiceList as $cArray)
{ {
@@ -827,7 +828,7 @@ class e107_user_extended
break; break;
case EUF_TEXTAREA : //textarea case EUF_TEXTAREA : //textarea
return "<textarea {$include} name='{$fname}' {$required} >{$curval}</textarea>"; return "<textarea id='{$fid}' {$include} name='{$fname}' {$required} >{$curval}</textarea>";
break; break;
case EUF_DATE : //date case EUF_DATE : //date
@@ -844,7 +845,7 @@ class e107_user_extended
$lanlist = e107::getLanguage()->installed(); $lanlist = e107::getLanguage()->installed();
sort($lanlist); sort($lanlist);
$ret = "<select {$include} name='{$fname}' {$required} >\n"; $ret = "<select {$include} id='{$fid}' name='{$fname}' {$required} >\n";
$ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it. $ret .= "<option value=''>&nbsp;</option>\n"; // ensures that the user chose it.
foreach($lanlist as $choice) foreach($lanlist as $choice)
{ {

View File

@@ -1,4 +1,4 @@
/* global $ */
$(document).ready(function() $(document).ready(function()
{ {
@@ -37,8 +37,8 @@ $(document).ready(function()
$(".e-comment-submit").live("click", function(){ $(".e-comment-submit").live("click", function(){
var url = $(this).attr("data-target"); var url = $(this).attr("data-target");
var sort = $(this).attr("data-sort"); var sort = $(this).attr("data-sort");
var pid = parseInt($(this).attr("data-pid")); var pid = parseInt($(this).attr("data-pid"));
var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form"; var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form";
var data = $('form'+formid).serialize() ; var data = $('form'+formid).serialize() ;
@@ -231,7 +231,7 @@ $(document).ready(function()
url: url + '?ajax_used=1&mode=delete', url: url + '?ajax_used=1&mode=delete',
data: { itemid: sp[3] }, data: { itemid: sp[3] },
success: function(data) { success: function(data) {
var a = $.parseJSON(data); var a = $.parseJSON(data);
if(!a.error) if(!a.error)
{ {
@@ -248,23 +248,23 @@ $(document).ready(function()
$(".e-comment-approve").live("click", function(){ $(".e-comment-approve").live("click", function(){
var url = $(this).attr("data-target"); var url = $(this).attr("data-target");
var sp = $(this).attr('id').split("-"); var sp = $(this).attr('id').split("-");
var id = "#comment-status-" + sp[3]; var id = "#comment-status-" + sp[3];
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: url + '?ajax_used=1&mode=approve', url: url + '?ajax_used=1&mode=approve',
data: { itemid: sp[3] }, data: { itemid: sp[3] },
success: function(data) { success: function(data) {
var a = $.parseJSON(data); var a = $.parseJSON(data);
if(!a.error) if(!a.error)
{ {
//TODO modify status of html on page. //TODO modify status of html on page
$(id).text(a.html) $(id).text(a.html)
.fadeIn('slow') .fadeIn('slow')
.addClass('e-comment-edit-success'); //TODO another class? .addClass('e-comment-edit-success'); //TODO another class?
@@ -289,28 +289,28 @@ $(document).ready(function()
$(".e-rate-thumb").live("click", function(){ $(".e-rate-thumb").live("click", function(){
var src = $(this).attr("href"); var src = $(this).attr("href");
var thumb = $(this); var thumb = $(this);
var tmp = src.split('#'); var tmp = src.split('#');
var id = tmp[1]; var id = tmp[1];
var src = tmp[0]; var src = tmp[0];
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: src, url: src,
data: { ajax_used: 1, mode: 'thumb' }, data: { ajax_used: 1, mode: 'thumb' },
dataType: "html", dataType: "html",
success: function(html) { success: function(html) {
if(html == '') if(html === '')
{ {
return false; return false;
} }
var tmp = html.split('|'); var tmp = html.split('|');
up= tmp[0]; up= tmp[0];
down = tmp[1]; down = tmp[1];
$('#'+id +'-up').text(up); $('#'+id +'-up').text(up);
$('#'+id +'-down').text(down); $('#'+id +'-down').text(down);
@@ -323,4 +323,30 @@ $(document).ready(function()
}); });
/* Switch to Tab containing invalid form field. */
$('input[type=submit],button[type=submit]').on('click', function() {
var id = $(this).closest('form').attr('id'), found = false;
$('#'+ id).find(':invalid').each(function (index, node) {
var tab = $('#'+node.id).closest('.tab-pane').attr('id');
// console.log(node.id);
if(tab && (found === false))
{
$('a[href="#'+tab+'"]').tab('show');
found = true;
}
});
return true;
});
}); });