We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 862
    • 7 Posts
    I have a problem with plugin creation. I need to modify content of 'content' field OnBeforeDocFormSave and then save a resource. It works, and the field in DB become saved successfully, but the field in a form remains unchanged because a data was sent via AJAX. I see the changes only after reloading the page.

    How do I fill the form with modified values of fields without reloading the page?

    or

    How do I turn off AJAX for resource editor?
      • 37743
      • 49 Posts
      Without the source I'm having to be a bit vague (apologies) but you would need to get the Ext id from the panel source (/manager/assets/widgets/resource/modx.panel.resource.js I think for the main resource edit panel) . With this id you should just be able to call
      Ext.getCmp('field-id-here').setValue('new value')

      This assumes the javascript environment has access to the new values. Could you post a bit more info and I'll see if I can be a bit more specific?
        • 862
        • 7 Posts
        $eventName = $modx->event->name;
        switch($eventName) {
            case 'OnBeforeDocFormSave':
                $text = $resource->get('content');
                $text = str_replace('aaa', 'bbb', $text);
                $resource->set('content', $text);
                break;
            case 'OnDocFormSave':
                // here I want to see the new value of 'content' 
                // in related textarea in admin panel, 
                // but I don't know how to do it
                break;
        }
          • 37743
          • 49 Posts
          The issue is that the save is done via Ajax rather than a page request. This means you're probably gonna have to get down and dirty with the manager javascript aswell.

          3 possibilities I can see:

          • Hack the existing modDocument js (Dirty with a capital D, avoid where poss)
          • Extend modDocument class and related javascript to add the additional functionality (A lot of heavy work for what is probably a fairly simple plugin)
          • There might be a way to force the data to refresh via the plugin php. I know if (for instance) the resource type is changed then the page refreshes onSave. Not sure if this is handled by php or js though. If it is php, this is your best bet. I'll see if I can narrow anything down for you.