Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max length counter support added to tutor settings #504

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/react/admin-dashboard/segments/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,28 @@ document.addEventListener('DOMContentLoaded', function () {
showHideToggleChildren($(this))
})

/**
* Maxlength counter for Textarea and Text field.
* @since 2.2.3
*/
let maxLengthTargets = $('.tutor-option-field-input textarea[maxlength], .tutor-option-field-input input[maxlength]')
maxLengthTargets.each(function () {
let el = $(this),
max = $(this).attr('maxlength'),
len = $(this).val().length,
text = `${len}/${max}`;

el.css('margin-right', 0)
$(this).parent().append(`<div class="tutor-field-maxlength-info tutor-mr-4 tutor-fs-8 tutor-color-muted">${text}</div>`)
});

maxLengthTargets.keyup(function () {
let el = $(this),
max = $(this).attr('maxlength'),
len = $(this).val().length,
text = `${len}/${max}`;

el.parent().find('.tutor-field-maxlength-info').text(text)
})

});
2 changes: 1 addition & 1 deletion classes/Options_V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
wp_send_json_error( tutor_utils()->error_message() );
}

$reset_fields = $return_fields = $return_fields_group = array();

Check failure on line 306 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

Assignments must be the first block of code on a line

Check failure on line 306 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

Assignments must be the first block of code on a line
$reset_page = Input::post( 'reset_page' );
$setting_data = $this->get_setting_fields()['option_fields'][ $reset_page ]['blocks'];

Expand Down Expand Up @@ -400,7 +400,7 @@

do_action( 'tutor_option_save_before' );

$option = (array) tutor_utils()->array_get( 'tutor_option', $_POST, array() );

Check failure on line 403 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

Processing form data without nonce verification.

$option = tutor_utils()->sanitize_recursively( $option, array( 'email_footer_text' ) );

Expand Down Expand Up @@ -482,7 +482,7 @@
* @return void
*/
public function load_settings_page() {
extract( $this->get_setting_fields() );

Check failure on line 485 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

extract() usage is highly discouraged, due to the complexity and unintended issues it might cause.

if ( ! $template_path ) {
$template_path = tutor()->path . '/views/options/settings.php';
Expand All @@ -508,7 +508,7 @@
$lesson_key = $this->get( 'lesson_permalink_base', 'lessons' );
$course_base = tutor_utils()->get_option( 'course_permalink_base', tutor()->course_post_type );
$course_url = site_url() . '/<code>' . $course_base . '</code>/sample-course';
$lesson_url = site_url() . '/' . $course_base . '/' . 'sample-course/<code>' . $lesson_key . '</code>/sample-lesson/';

Check failure on line 511 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

String concat is not required here; use a single string instead
$student_url = tutor_utils()->profile_url( 0, false );

$methods_array = array();
Expand Down Expand Up @@ -899,7 +899,7 @@
'type' => 'textarea',
'label' => __( 'Fee Description', 'tutor' ),
'placeholder' => __( 'Fee Description', 'tutor' ),
'desc' => __( 'Set a description for the fee that you are deducting. Make sure to give a reasonable explanation to maintain transparency with your site’s instructors (within 200-character limit).', 'tutor' ),
'desc' => __( 'Set a description for the fee that you are deducting. Make sure to give a reasonable explanation to maintain transparency with your site’s instructors.', 'tutor' ),
'maxlength' => 200,
'rows' => 5,
'default' => 'Maintenance Fees',
Expand Down Expand Up @@ -1538,7 +1538,7 @@
// 'label' => __('Course Permalink Base', 'tutor'),
// 'default' => tutor()->course_post_type,
// 'desc' => $course_url,
// ),

Check failure on line 1541 in classes/Options_V2.php

View workflow job for this annotation

GitHub Actions / WPCS

Inline comments must end in full-stops, exclamation marks, or question marks
array(
'key' => 'lesson_permalink_base',
'type' => 'text',
Expand Down
Loading