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

NEW Show icons on tabs with invalid form field values #1111

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Sep 17, 2020

Enhancement for #1109

image

Youtube video demo

Used to communicate which tabs have invalid form field values

Design

Design elements implemented:

  • Tab icons
  • Red alert banner

Design elements not implemented:

  • 'X' on the red alert banner to dismiss the banner
  • New style for the invalid form field elements (red border, red text underneath)

TODO before peer review:

TODO testing

  • Have agreed with @brynwhyman that we'll skip doing automated testing before merge on this one, simply because of the need to add frameworktest to the silverstripe-admin .travis.yml to get a custom page type for testing. We'll do this in a subsequent issue.
  • Include details of the custom page type as a comment on this pull-request
  • Write out the behat test as a comment

TODO before closing:

  • Design review (Sacha said she'd like to do this after CSS has been peer reviewed)
  • Push translation changes to transifix

@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch 2 times, most recently from 645873e to 9842494 Compare September 17, 2020 23:42
@emteknetnz emteknetnz changed the title Pulls/1.6/invalid tab icons NEW Show icons on tabs with invalid form field values Sep 17, 2020
@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from 9842494 to a516678 Compare September 18, 2020 01:30
@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from a516678 to 60eaece Compare September 18, 2020 02:27
client/lang/src/en.json Outdated Show resolved Hide resolved
@emteknetnz
Copy link
Member Author

emteknetnz commented Sep 18, 2020

Test only multi-tab page type to be added to frameworktest in a subsequent pull-request and can be used for manual testing

I'm not sure how to automatically test the 2 validate() functions, particularly the $result->addError() scenario

There are 3 failed validation scenarios:

  1. A required field in getCMSValidator() is blank in the CMS
  2. In validate() $result->addFieldError is not comment out
  3. In validate() $result->addError is not comment out
<?php

namespace {

    use SilverStripe\CMS\Model\SiteTree;
    use SilverStripe\Forms\RequiredFields;
    use SilverStripe\Forms\TextField;

    class MultiTabPage extends SiteTree
    {
        private static $db = [
            'SecondTabFirstField' => 'Varchar(50)',
            'ThirdTabFirstField' => 'Varchar(50)',
            'ThirdTabSecondField' => 'Varchar(50)',
            'FourthTabFirstField' => 'Varchar(50)',
            'SettingsTabFirstField' => 'Varchar(50)',
        ];

        private static $has_one = [];

        public function getCMSFields()
        {
            $fields = parent::getCMSFields();
            $fields->addFieldToTab("Root.Second", TextField::create("SecondTabFirstField"));
            $fields->addFieldToTab("Root.Third", TextField::create("ThirdTabFirstField"));
            $fields->addFieldToTab("Root.Third", TextField::create("ThirdTabSecondField"));
            $fields->addFieldToTab("Root.Fourth", TextField::create("FourthTabFirstField"));
            return $fields;
        }

        public function getSettingsFields()
        {
            $fields = parent::getSettingsFields();
            $fields->addFieldToTab("Root.Settings", TextField::create('SettingsTabFirstField'));
            return $fields;
        }

        public function getCMSValidator()
        {
            return new RequiredFields([
                'ThirdTabFirstField',
                'FourthTabFirstField',
                'SettingsTabFirstField'
            ]);
        }

        public function validate()
        {
            $result = parent::validate();

            // validation error on speicific form field - uncomment to test
            $result->addFieldError('SecondTabFirstField', 'This field cannot exist.');

            // general validation error on form  - uncomment to test
            // try testing with `->addFieldError` line above commented out and not comment out
            $result->addError('This page cannot exist.');

            return $result;
        }
    }
}

@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from 60eaece to bab66e1 Compare September 18, 2020 03:08
@emteknetnz
Copy link
Member Author

emteknetnz commented Sep 18, 2020

Behat test should look something like this. It should be in the silverstripe/silverstripe-cms repo which deals with page types, rather than here in silverstripe/silverstripe-admin

Will also need to create a function probably in FixtureContext.php for creating multi-tab pages. However given the pagetype should only exist in frameworktest, it gets quite messy

We should discuss before implementation if we even want to do this at all.

Feature: Multi-tab page validation icons
  As a content author
  I want to see which tabs have form fields that failed validation
  So that I know what I need to fix before saving

  Background:
    Given a "multi-tab page" "My MultiTab Page"

  Scenario: I can see tab validation icons
    Given I go to "/my-multitab-page"
    When I press the "Save" button
    Then I should not see an invalid tab icon on "Second tab"
    Then I should see an invalid tab icon on "Third tab"
    Then I should see an invalid tab icon on "Fourth tab"
    When I click on "Third tab"
    And I fill in "Third tab first field" with "abc"
    When I press the "Save" button
    Then I should not see an invalid tab icon on "Second tab"
    Then I should not see an invalid tab icon on "Third tab"
    Then I should see an invalid tab icon on "Fourth tab"
    When I click on "Third tab"
    And I fill in "Fourth tab first field" with "def"
    When I press the "Save" button
    Then I should not see an invalid tab icon on "Second tab"
    Then I should not see an invalid tab icon on "Third tab"
    Then I should not see an invalid tab icon on "Fourth tab"

@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from bab66e1 to d5fae61 Compare September 18, 2020 04:34
@emteknetnz emteknetnz marked this pull request as ready for review September 18, 2020 04:43
@emteknetnz emteknetnz assigned emteknetnz and unassigned emteknetnz Sep 18, 2020
@emteknetnz emteknetnz linked an issue Sep 20, 2020 that may be closed by this pull request
4 tasks
@emteknetnz emteknetnz mentioned this pull request Sep 20, 2020
4 tasks
@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch 5 times, most recently from aee68d5 to b54b057 Compare September 22, 2020 03:35
Copy link
Member

@Cheddam Cheddam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback on the implementation; also found another edgecase - if a DataObject::validate() method triggers addFieldError() but not addError(), none of the new behaviour triggers.

I've also noticed that addMessage and addFieldMessage don't render at all, but this seems to be an existing bug, so we can raise a separate issue for that.

client/src/legacy/LeftAndMain.EditForm.js Show resolved Hide resolved
Comment on lines 703 to 697
align-self: flex-start;
margin-top: 12px;
margin-left: -4px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using flex, I suggest taking this icon out of the standard flow, as the current approach pushes away the tab to the right.

Suggested change
align-self: flex-start;
margin-top: 12px;
margin-left: -4px;
position: relative;
top: 12px;
right: 4px;

(You should also be able to drop out the other flex rules above.)

Copy link
Member Author

@emteknetnz emteknetnz Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the horizontally moving tabs is actually intentional, otherwise you end up with not much whitespace between tabs

position: absolute
image

flex
image

@sachajudd ?

Copy link
Contributor

@sachajudd sachajudd Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I peer reviewed this yesterday with @Cheddam and we would like to keep the spacing between tabs consistent as seen per designs. I didn't notice this in our initial design review together.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

client/src/legacy/LeftAndMain.EditForm.js Outdated Show resolved Hide resolved
client/src/legacy/LeftAndMain.EditForm.js Outdated Show resolved Hide resolved
client/src/legacy/LeftAndMain.EditForm.js Outdated Show resolved Hide resolved
@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from b54b057 to 5701629 Compare September 23, 2020 02:06
Copy link
Member

@Cheddam Cheddam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more minor items - once these are addressed (along with the existing styling feedback) we should be good to merge.

client/src/legacy/LeftAndMain.EditForm.js Show resolved Hide resolved
client/src/legacy/LeftAndMain.EditForm.js Outdated Show resolved Hide resolved
@emteknetnz emteknetnz force-pushed the pulls/1.6/invalid-tab-icons branch from 5701629 to ba2aad5 Compare September 23, 2020 23:23
Copy link
Contributor

@sachajudd sachajudd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved from a UX POV

Copy link
Contributor

@dnsl48 dnsl48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@emteknetnz emteknetnz merged commit d57534c into silverstripe:1.6 Sep 24, 2020
@emteknetnz emteknetnz deleted the pulls/1.6/invalid-tab-icons branch September 24, 2020 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation icon on form tab
4 participants