fix: validations and UI

This commit is contained in:
Jannat Patel
2023-05-11 12:01:32 +05:30
parent 0e444ab7d3
commit c3f3a110c0
5 changed files with 40 additions and 32 deletions

View File

@@ -58,7 +58,7 @@
}, },
{ {
"fieldname": "description", "fieldname": "description",
"fieldtype": "Markdown Editor", "fieldtype": "Text Editor",
"label": "Description", "label": "Description",
"reqd": 1 "reqd": 1
}, },
@@ -261,7 +261,7 @@
} }
], ],
"make_attachments_public": 1, "make_attachments_public": 1,
"modified": "2023-05-09 17:08:19.763405", "modified": "2023-05-11 17:08:19.763405",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Course", "name": "LMS Course",

View File

@@ -53,3 +53,4 @@ lms.patches.v0_0.add_evaluator_to_assignment #09-04-2023
lms.patches.v0_0.share_certificates lms.patches.v0_0.share_certificates
execute:frappe.delete_doc("Web Form", "class", ignore_missing=True, force=True) execute:frappe.delete_doc("Web Form", "class", ignore_missing=True, force=True)
lms.patches.v0_0.amend_course_and_lesson_editor_fields lms.patches.v0_0.amend_course_and_lesson_editor_fields
lms.patches.v0_0.convert_course_description_to_html #11-05-2023

View File

@@ -1400,13 +1400,13 @@ pre {
.course-overlay-card { .course-overlay-card {
background-color: white; background-color: white;
border-radius: var(--border-radius-lg); border-radius: var(--border-radius-lg);
box-shadow: var(--shadow-sm); border: 1px solid var(--gray-300);
overflow: auto; overflow: auto;
width: fit-content; width: fit-content;
position: absolute; position: absolute;
top: 10%; top: 10%;
right: 7%; right: 7%;
max-width: 350px; width: 350px;
z-index: 4; z-index: 4;
} }

View File

@@ -129,14 +129,12 @@
{{ format_number(get_students(course.name) | length) }} {{ _("Enrolled") }} {{ format_number(get_students(course.name) | length) }} {{ _("Enrolled") }}
</div> </div>
{% if get_lessons(course.name) | length %}
<div class="vertically-center mb-3"> <div class="vertically-center mb-3">
<svg class="icon icon-md mr-1"> <svg class="icon icon-md mr-1">
<use href="#icon-education"></use> <use href="#icon-education"></use>
</svg> </svg>
{{ get_lessons(course.name, None, False) }} {{ _("Lessons") }} {{ get_lessons(course.name, None, False) }} {{ _("Lessons") }}
</div> </div>
{% endif %}
{% if course.enable_certification %} {% if course.enable_certification %}
<div class="vertically-center mb-3"> <div class="vertically-center mb-3">
@@ -253,24 +251,25 @@
</a> </a>
{% elif course.grant_certificate_after == "Completion" and progress == 100 %} {% elif course.grant_certificate_after == "Completion" and progress == 100 %}
<div class="btn btn-secondary wide-button is-secondary mt-2" id="certification" data-course="{{ course.name }}"> <div class="btn btn-secondary wide-button mt-2" id="certification" data-course="{{ course.name }}">
{{ _("Get Certificate") }} {{ _("Get Certificate") }}
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
</div>
<div>
{% if is_instructor(course.name) or has_course_moderator_role() %} {% if is_instructor(course.name) or has_course_moderator_role() %}
<a class="btn btn-default btn-sm pull-right ml-2" title="Edit Course" href="/courses/{{ course.name }}/edit"> <a class="btn btn-secondary wide-button mt-2" title="Edit Course" href="/courses/{{ course.name }}/edit">
<svg class="icon icon-md"> <!-- <svg class="icon icon-md">
<use href="#icon-edit"></use> <use href="#icon-edit"></use>
</svg> </svg> -->
{{ _("Edit") }}
</a> </a>
{% endif %} {% endif %}
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -94,20 +94,28 @@ const validate_mandatory = () => {
let input = $(el).closest(".field-group").find(".field-input"); let input = $(el).closest(".field-group").find(".field-input");
if (input.length && input.val().trim() == "") { if (input.length && input.val().trim() == "") {
if (input.siblings(".error-message").length == 0) { if (input.siblings(".error-message").length == 0) {
scroll_to_element(input);
throw_error(el, input);
}
throw `${$(el).text().trim()} is mandatory`;
}
});
if (!strip_html(this.description.fields_dict["description"].value)) {
scroll_to_element("#description");
throw_error(
"#description",
this.description.fields_dict["description"].parent
);
throw "Description is mandatory";
}
};
const throw_error = (el, input) => {
let error = document.createElement("p"); let error = document.createElement("p");
error.classList.add("error-message"); error.classList.add("error-message");
error.innerText = `Please enter a ${$(el).text().trim()}`; error.innerText = `Please enter a ${$(el).text().trim()}`;
$(error).insertAfter($(input)); $(error).insertAfter($(input));
}
scroll_to_element(input);
throw "Mandatory field missing";
}
});
console.log(this.description.fields_dict["description"].value);
if (!this.description.fields_dict["description"].value) {
scroll_to_element("#description");
frappe.throw(__(`Please enter a description`));
}
}; };
const scroll_to_element = (element) => { const scroll_to_element = (element) => {