New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • I'm interested in adding validation logic to test for uniqueness of records depending on their template and a certain set of fields to test against. The records in question contain data for contacts of two types—individuals and organizations—each having typical contact fields set up as TVs. The validation needs to prompt for a confirmation when a similar (enough) record is found to that which is being added/updated. For instance, a manager might attempt to create a resource for an individual with the same name but different email address as an existing one. In this case, I'd like to trigger a confirmation dialog saying something like:
    "A record with similar information was found: [firstname] [lastname] [email]. If you're sure the record you're saving is unique, click OK. Otherwise, click cancel."

    What I've arrived at as a possible solution is to override the and classes to add a handler to the save button to call a custom validation method. What I'm stuck on is figuring out the code needed to continue the normal process should the user press "OK." Here's an outline of the create override:

    (function() {
    	var origGetButtons =;
    	Ext.override(, {
    	    getButtons: function (cfg) {
    	    	var items = origGetButtons.apply(this, arguments);
    	    	items[0].handler = this.validateContact;
    	    	return items;
    	    validateContact: function () {
    	    	// Ajax request to connector/processor with validation php, returning 'unique' or 'confirm' (with additional data)
    	    		// code to continue process???
    	    	} else {
    				Ext.Msg.confirm('Validation Message','The record you are saving may be a duplicate. Continue?',function(e) {
    	                if (e == 'yes') {
    	                    // code to continue process???
    	                } else {
    						// not sure if anything is needed here if staying on the current create/edit page

    For reference the subclass (from modext/sections/resource/create.js): = function(config) {
        config = config || {};
            url: MODx.config.connector_url
            ,formpanel: 'modx-panel-resource'
            ,id: 'modx-page-update-resource'
            ,which_editor: 'none'
            ,action: 'resource/create'
        	,buttons: this.getButtons(config)
            ,components: [{
                xtype: config.panelXType || 'modx-panel-resource'
                ,renderTo: config.panelRenderTo || 'modx-panel-resource-div'
                ,resource: 0
                ,record: config.record
                ,publish_document: config.publish_document
                ,show_tvs: config.show_tvs
                ,mode: config.mode
                ,url: config.url
        getButtons: function(cfg) {
            var btns = [];
            if (cfg.canSave == 1) {
                    process: 'resource/create'
                    ,reload: true
                    ,text: _('save')
                    ,id: 'modx-abtn-save'
                    ,method: 'remote'
                    ,keys: [{
                        key: MODx.config.keymap_save || 's'
                        ,ctrl: true
                text: _('cancel')
                ,id: 'modx-abtn-cancel'
                text: _('help_ex')
                ,id: 'modx-abtn-help'
                ,handler: MODx.loadHelpPane
            return btns;

    My sense is there's a simple solution here...any pointers are much appreciated!