Skip to content

Commit

Permalink
Added advance question setting named Minimum Characters
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed Jan 30, 2024
1 parent f82ebe5 commit fa276c7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
8 changes: 8 additions & 0 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ function qmnValidation(element, quiz_form_id) {
show_result_validation = false;
}
}
if ( jQuery(this).hasClass('mlw_answer_open_text') || jQuery(this).hasClass('qmn_fill_blank') || jQuery(this).hasClass('mlw_answer_number')) {
if (jQuery.trim(this.value).length < jQuery(this).attr('minlength')) {
var minlength_error = error_messages.minlength_error_text;
minlength_error = minlength_error.replace('%minlength%', jQuery(this).attr('minlength'));
qmnDisplayError(minlength_error, jQuery(this), quiz_form_id);
show_result_validation = false;
}
}
if (jQuery(this).attr('class').indexOf('mlwMaxLength') !== -1 && this.value !== "") {
// Remove any trailing and preceeding space.
if (jQuery.trim(this.value).length > jQuery(this).attr('maxlength')) {
Expand Down
9 changes: 9 additions & 0 deletions php/admin/options-page-questions-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ class="save-page-button button button-primary"><?php esc_html_e( 'Save Questions
'show' => '3, 5, 7, 14' . $show_limit_text,
'documentation_link' => qsm_get_plugin_link( 'docs/creating-quizzes-and-surveys/adding-and-editing-questions/', 'quiz_editor', 'limit_text', 'quizsurvey-limit_text_doc' ),
),
'min_text_length' => array(
'heading' => __( 'Minimum Characters', 'quiz-master-next' ),
'label' => __( 'Minimum number of characters required', 'quiz-master-next' ),
'type' => 'text',
'priority' => '11',
'default' => '',
'show' => '3, 5, 7, 14',
'documentation_link' => qsm_get_plugin_link( 'docs/creating-quizzes-and-surveys/adding-and-editing-questions/', 'quiz_editor', 'min_text_length', 'quizsurvey-min_text_length_doc' ),
),
'limit_multiple_response' => array(
'heading' => __( 'Limit Multiple choice', 'quiz-master-next' ),
'label' => __( 'Maximum number of choice selection allowed', 'quiz-master-next' ),
Expand Down
6 changes: 4 additions & 2 deletions php/question-types/qsm-question-type-fill-in-the-blanks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function qmn_fill_blank_display( $id, $question, $answers ) {
'height' => true,
'min' => true,
'max' => true,
'minlenght' => true,
'minlength' => true,
'maxlength' => true,
'name' => true,
'pattern' => true,
Expand All @@ -36,14 +36,16 @@ function qmn_fill_blank_display( $id, $question, $answers ) {
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$min_text_length = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'min_text_length' );
$autofill_att = $autofill ? "autocomplete='off' " : '';
$limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
$min_text_length_att = $min_text_length ? "minlength='" . $min_text_length . "' " : '';
if ( 0 == $required ) {
$mlw_require_class = 'mlwRequiredText';
} else {
$mlw_require_class = '';
}
$input_text = '<input ' . $autofill_att . $limit_text_att . " type='text' class='qmn_fill_blank $mlw_require_class' name='question" . $id . "[]' />";
$input_text = '<input ' . $min_text_length_att . $autofill_att . $limit_text_att . " type='text' class='qmn_fill_blank $mlw_require_class' name='question" . $id . "[]' />";
$input_text = apply_filters( 'qsm_fill_in_blanks_input_after', $input_text, $id, $question, $answers, $mlw_require_class );
if ( strpos( $question, '%BLANK%' ) !== false ) {
$question = str_replace( '%BLANK%', $input_text, do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
Expand Down
7 changes: 4 additions & 3 deletions php/question-types/qsm-question-type-number.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*/
function qmn_number_display( $id, $question, $answers ) {
global $mlwQuizMasterNext;
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$min_text_length = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'min_text_length' );
if ( 0 == $required ) {
$mlw_require_class = 'mlwRequiredNumber';
} else {
Expand All @@ -25,7 +26,7 @@ function qmn_number_display( $id, $question, $answers ) {
$new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
qsm_question_title_func( $question, '', $new_question_title, $id );
?>
<input type="number" class="mlw_answer_number <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>" oninput="checkMaxLength(this)" <?php endif; ?> />
<input type="number" class="mlw_answer_number <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>" oninput="checkMaxLength(this)" <?php endif; ?> <?php if ( $min_text_length ) : ?>minlength="<?php echo esc_attr( $min_text_length ); ?>"<?php endif; ?> />
<?php
echo apply_filters( 'qmn_number_display_front', '', $id, $question, $answers );
}
Expand Down
3 changes: 2 additions & 1 deletion php/question-types/qsm-question-type-paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function qmn_large_open_display( $id, $question, $answers ) {
global $mlwQuizMasterNext;
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$min_text_length = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'min_text_length' );
if ( 0 == $required ) {
$mlw_require_class = 'mlwRequiredText';
} else {
Expand All @@ -25,7 +26,7 @@ function qmn_large_open_display( $id, $question, $answers ) {
$new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
qsm_question_title_func( $question, '', $new_question_title, $id );
?>
<textarea class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" cols="70" rows="5" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>"<?php endif; ?> /></textarea>
<textarea class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" cols="70" rows="5" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>"<?php endif; ?> <?php if ( $min_text_length ) : ?>minlength="<?php echo esc_attr( $min_text_length ); ?>"<?php endif; ?> /></textarea>
<?php
echo apply_filters( 'qmn_large_open_display_front', '', $id, $question, $answers );
}
Expand Down
9 changes: 5 additions & 4 deletions php/question-types/qsm-question-type-short-answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
function qmn_small_open_display( $id, $question, $answers ) {
global $mlwQuizMasterNext;
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
$autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
$limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
$min_text_length = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'min_text_length' );
$autofill_att = $autofill ? "autocomplete='off' " : '';
if ( 0 == $required ) {
$mlw_require_class = 'mlwRequiredText';
Expand All @@ -27,7 +28,7 @@ function qmn_small_open_display( $id, $question, $answers ) {
$new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
qsm_question_title_func( $question, '', $new_question_title, $id );
?>
<input <?php echo esc_attr( $autofill_att ); ?> type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>"<?php endif; ?> />
<input <?php echo esc_attr( $autofill_att ); ?> type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" <?php if ( $limit_text ) : ?>maxlength="<?php echo esc_attr( $limit_text ); ?>"<?php endif; ?> <?php if ( $min_text_length ) : ?>minlength="<?php echo esc_attr( $min_text_length ); ?>"<?php endif; ?> />
<?php
echo apply_filters( 'qmn_small_open_display_front', '', $id, $question, $answers );
}
Expand Down

0 comments on commit fa276c7

Please sign in to comment.