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

Custom page's validation message doesn't display when the page is loaded via ajax #2230

Closed
1 task done
phalkunz opened this issue Aug 13, 2018 · 15 comments
Closed
1 task done

Comments

@phalkunz
Copy link
Contributor

phalkunz commented Aug 13, 2018

This is possibly an issue in the admin module. This happens when you load a custom page with required fields via ajax. On saving/publishing, the required field messages and the central warning message do not show up.

If you, however, select the custom page and reload the CMS, the validation messages work as expected.

Step to reproduce:

  1. Create custom page
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\TextField;

class TeamPage extends Page
{
    private static $db = [
        'TeamName' => 'Varchar',
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', TextField::create('TeamName'));
        return $fields;
    }

    public function getCMSValidator()
    {
        return RequiredFields::create(['TeamName']);
    }
}
  1. Log into the CMS
  2. Create a Team page
  3. Log out and log back in
  4. Now select the Team page you just created
  5. Leave the Team Name field blank and save the page
  6. You should see the validation message on the field and the central warning message "Validation error" but they are not showing!

Pull Requests

@chillu
Copy link
Member

chillu commented Oct 28, 2018

@phalkunz Can you run composer info? We need to know which version this appears in, Luke can't reproduce

@phalkunz
Copy link
Contributor Author

@chillu The version is 4.2.1

@maxime-rainville
Copy link
Contributor

I just gave it a go on 4.2.1. Everything seems to be working as expected for me.

Here's what it looks like for me https://youtu.be/n0slMPKzHBs

Am I doing something wrong?

@phalkunz
Copy link
Contributor Author

@maxime-rainville I think your steps to reproduce it is correct. Do you mind leaving it open for a week or so? I'll take make a note to test it again.

@maxime-rainville
Copy link
Contributor

Sure thing.

@phalkunz
Copy link
Contributor Author

@maxime-rainville Just gave it a try. Turned out if you log out and log back into you won't see the validation message on publishing the page. I'll update to the steps to reproduce it.

validation-msg

@maxime-rainville
Copy link
Contributor

I tried logging in and logging out like you did. But I still can't see it 😞

Are you seeing anything in the JS console log? Could you have a look at the network tab in your browser's dev tool and show me the HTTP request for the Save action?

@phalkunz
Copy link
Contributor Author

Request header:

POST /admin/pages/edit/EditForm/6/ HTTP/1.1
Host: cwp2.local
Connection: keep-alive
Content-Length: 4090
Accept: */*
Origin: http://cwp2.local
X-Requested-With: XMLHttpRequest
X-Pjax: CurrentForm,Breadcrumbs
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://cwp2.local/admin/pages/edit/show/6
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: cms-panel-collapsed-cms-menu=false; PHPSESSID=n3rgvat5tsi0nbvpf4knvlsi89

Form data:

Title: New Team Page
URLSegment: new-team-page
MenuTitle: New Team Page
Content: 
MetaDescription: 
ExtraMeta: 
TeamName: 
gridfield_relationsearch: 
RelatedPages[GridState]: {"GridFieldOrderableRows":{"enabled":true},"GridFieldAddRelation":null,"GridFieldSortableHeader":{"SortColumn":[]},"GridFieldPaginator":{"currentPage":1}}
Terms: 
NewComments[GridState]: {"GridFieldSortableHeader":{"SortColumn":[]},"GridFieldFilterHeader":{"Columns":[]},"GridFieldPaginator":{"currentPage":1}}
filter[NewComments][Name]: 
filter[NewComments][Email]: 
filter[NewComments][Created]: 
filter[NewComments][IsSpam]: 
bulkActionName: 
ApprovedComments[GridState]: {"GridFieldSortableHeader":{"SortColumn":[]},"GridFieldFilterHeader":{"Columns":[]},"GridFieldPaginator":{"currentPage":1}}
filter[ApprovedComments][Name]: 
filter[ApprovedComments][Email]: 
filter[ApprovedComments][Created]: 
filter[ApprovedComments][IsSpam]: 
bulkActionName: 
SpamComments[GridState]: {"GridFieldSortableHeader":{"SortColumn":[]},"GridFieldFilterHeader":{"Columns":[]},"GridFieldPaginator":{"currentPage":1}}
filter[SpamComments][Name]: 
filter[SpamComments][Email]: 
filter[SpamComments][Created]: 
filter[SpamComments][IsSpam]: 
bulkActionName: 
TriggeredWorkflowID: 
ClassName: TeamPage
ParentID: 1
SecurityID: 08e452c5fe283cf158f699e1dacf6e50c5c45c0e
ID: 6
AbsoluteLink: http://cwp2.local/home/new-team-page/
LiveLink: 
StageLink: http://cwp2.local/home/new-team-page/?stage=Stage
ArchiveWarningMessage: Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?
TreeTitle: <span class="jstree-pageicon page-icon class-TeamPage"></span><span class="item" data-allowedchildren="{&quot;Page&quot;:&quot;Page&quot;,&quot;TeamPage&quot;:&quot;Team Page&quot;,&quot;SilverStripe\\ErrorPage\\ErrorPage&quot;:&quot;Error Page&quot;,&quot;SilverStripe\\IFrame\\IFramePage&quot;:&quot;IFrame Page&quot;,&quot;SilverStripe\\Registry\\RegistryPage&quot;:&quot;Registry Page&quot;,&quot;CWP\\CWP\\PageTypes\\SitemapPage&quot;:&quot;Sitemap Page&quot;,&quot;SilverStripe\\Blog\\Model\\Blog&quot;:&quot;Blog&quot;,&quot;SilverStripe\\Blog\\Model\\BlogPost&quot;:&quot;Blog Post&quot;,&quot;SilverStripe\\CMS\\Model\\RedirectorPage&quot;:&quot;Redirector Page&quot;,&quot;SilverStripe\\CMS\\Model\\VirtualPage&quot;:&quot;Virtual Page&quot;,&quot;SilverStripe\\UserForms\\Model\\UserDefinedForm&quot;:&quot;User Defined Form&quot;,&quot;HomePage&quot;:&quot;Home Page&quot;,&quot;CWP\\CWP\\PageTypes\\EventHolder&quot;:&quot;Event Holder&quot;,&quot;CWP\\CWP\\PageTypes\\NewsHolder&quot;:&quot;News Holder&quot;,&quot;CWP\\CWP\\PageTypes\\EventPage&quot;:&quot;Event Page&quot;,&quot;CWP\\CWP\\PageTypes\\NewsPage&quot;:&quot;News Page&quot;,&quot;CWP\\CWP\\PageTypes\\FooterHolder&quot;:&quot;Footer Holder&quot;,&quot;SilverStripe\\Subsites\\Pages\\SubsitesVirtualPage&quot;:&quot;Subsites Virtual Page&quot;}">New Team Page</span><span class="badge status-addedtodraft" title="Page has not been published yet">Draft</span>
Action: split
action_publish: 1
BackURL: http://cwp2.local/admin/pages/edit/show/6

@maxime-rainville
Copy link
Contributor

I think I'm getting it now. I was testing on a plain SS4 installed. I switch to testing it on CWP kitchen sink, which seems to bring out the issue.

Basically, the request and response we're getting back is fine. It just looks like the front end is not doing anything with it.

@maxime-rainville
Copy link
Contributor

I think I found where the problem is.

For some reason on this jQuery.ajax call the success handler is not being called after you've navigated between pages in the tree view. The complete handler is however.

      jQuery.ajax(jQuery.extend({
        headers: {"X-Pjax" : "CurrentForm,Breadcrumbs"},
        url: form.attr('action'),
        data: formData,
        type: 'POST',
        complete: function() {
          clearButton()
        },
        success: function(data, status, xhr) {
          clearButton();
          form.removeClass('changed'); // TODO This should be using the plugin API
          if(callback) callback(data, status, xhr);


          var newContentEls = self.handleAjaxResponse(data, status, xhr);
          if(!newContentEls) return;


          newContentEls.filter('form').trigger('aftersubmitform', {status: status, xhr: xhr, formData: formData});
        }
      }, ajaxOptions));

https://github.com/silverstripe/silverstripe-admin/blob/7a9920bfa63a95d5b43914fa7a6680925dcc24a4/client/src/legacy/LeftAndMain.js#L498-L516

@maxime-rainville
Copy link
Contributor

I think I found the problematic module that's breaking things. It's colymba/gridfield-bulk-editing-tools. If you remove its JS, the publish action works fine.

I had a similar problem a few month ago with that specific bit of code while trying to implement a lazy loadable gridfield.

@maxime-rainville
Copy link
Contributor

silverstripe/silverstripe-admin#769 will provide a fix that allows admin to be more resilient to AJAX errors.

@bergice Did you investigate what the issue with colymba/gridfield-bulk-editing-tools was? That's a supported module, so we should endeavour to fix the specific problem it has. Or we can raise an issue on the repo and let the CC looks into it.

@robbieaverill
Copy link
Contributor

That PR is merged, does it resolve this?

@maxime-rainville
Copy link
Contributor

There's still an issue with colymba/gridfield-bulk-editing-tools. The fix prevents that issue from breaking unrelated things, but we should fix colymba/gridfield-bulk-editing-tools as well.

@maxime-rainville
Copy link
Contributor

Outstanding points have been split into silverstripe/silverstripe-gridfield-bulk-editing-tools#188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants