Skip to content

Commit

Permalink
Add an asterisk to label of required TVs (#16594)
Browse files Browse the repository at this point in the history
### What does it do?
Adds asterix automatically to a TV that has `allowBlank: false` set.


![tv_req_1](https://github.com/user-attachments/assets/5f9029ca-b076-4f56-b545-c40ffcd3fa32)


![tv_req_2](https://github.com/user-attachments/assets/296eac3a-d0ea-4ace-a336-284dfdd42f87)

### Why is it needed?
Required TVs are no different from regular ones. Only when saving the
resource, required TVs are marked with a message, **which is
inconvenient**.

p.s. For the 3.x branch, this behavior already exists, and it would not
be superfluous for 2.x as well.

### Related issue(s)/PR(s)
#16593
#14522
  • Loading branch information
Ruslan-Aleev authored Oct 30, 2024
1 parent b0a6a13 commit 222a770
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions manager/assets/modext/core/modx.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Ext.extend(MODx,Ext.Component,{

,startup: function() {
this.initQuickTips();
this.initMarkRequiredTVs();
this.request = this.getURLParameters();
this.Ajax = this.load({ xtype: 'modx-ajax' });
Ext.override(Ext.form.Field,{
Expand Down Expand Up @@ -95,6 +96,35 @@ Ext.extend(MODx,Ext.Component,{
});
}

,initMarkRequiredTVs: function() {
var markdom = '<span class=\"required\">*</span> ';

var MarkRequiredTVPlugin = function (config) {
config = config || {};
Ext.apply(config, {
init: function(cmp) {
if (cmp.allowBlank !== false) return;

var tv = cmp.applyTo || cmp.id;
if (tv && tv.match(/^tv[\d]*$/i)) {
var label = document.getElementById(tv+'-caption');
var html = label.innerHTML+markdom;
label.innerHTML = html;
}
}
});
MarkRequiredTVPlugin.superclass.constructor.call(this, config);
}
Ext.extend(MarkRequiredTVPlugin, Ext.BoxComponent);
Ext.ComponentMgr.registerPlugin('markrequiredfields',MarkRequiredTVPlugin);

if (!Array.isArray(Ext.form.Field.prototype.plugins)) {
Ext.form.Field.prototype.plugins = [];
}
var plugins = Ext.form.Field.prototype.plugins;
Ext.form.Field.prototype.plugins = Ext.form.Field.prototype.plugins.concat(['markrequiredfields'], plugins);
}

,getURLParameters: function() {
var arg = {};
var href = window.location.search;
Expand Down

0 comments on commit 222a770

Please sign in to comment.