silverstripe / silverstripe-userforms

UserForms module provides a visual form builder for the Silverstripe CMS. No coding required to build forms such as contact pages.
BSD 3-Clause "New" or "Revised" License
135 stars 225 forks source link

Save and publish buttons broken in SS4.2.1 #805

Closed elkebe closed 5 years ago

elkebe commented 6 years ago

Create a new UserDefinedForm in CMS, add some fields, publish. Click one of the fields to edit it. Scroll to bottom of page and you'll see the save and publish buttons are broken. If the publish button is clicked, you get redirected to page not found (if save button is used instead, it works and form can be published from main page view).

screen shot 2018-08-29 at 5 05 31 pm

Web inspector shows: TypeError: $(this).button is not a function. (In '$(this).button('destroy')', '$(this).button' is undefined) in dropdown_form_action.js:47

NightJar commented 6 years ago

Hi @elkebe, thanks for taking the time to report this issue. Can you please also provide a list of other modules you have installed (c.f. composer show), and whether or not you have any customisations to Page.php in your project (or if this is a custom subclass of UserDefinedForm)?

elkebe commented 6 years ago

Installed modules:

axllent/silverstripe-email-obfuscator           2.0.3              Email obfuscator for SilverStripe
axllent/silverstripe-favicons                   2.0.1              Simplistic templating for adding favicons for multiple de...
betterbrief/silverstripe-googlemapfield         v2.1.0             Save locations using latitude/longitude DataObject fields.
bhofstaetter/silverstripe-dependentlistboxfield dev-master 83f7ac1 A silverstripe listbox field that has it's options popula...
composer/ca-bundle                              1.1.2              Lets you find a path to the system CA bundle, and include...
composer/installers                             v1.5.0             A multi-framework Composer library installer
doctrine/instantiator                           1.0.5              A small, lightweight utility to instantiate objects in PH...
dorsetdigital/silverstripe-simpleinstagram      v1.0.1             Retrieves the Instagram feed for a given user for embeddi...
embed/embed                                     v3.3.5             PHP library to retrieve page info using oembed, opengraph...
gdmedia/ss-auto-git-ignore                      1.0.2              A Composer post-update-cmd script to automatically add Co...
guzzlehttp/guzzle                               6.3.3              Guzzle is a PHP HTTP client library
guzzlehttp/promises                             v1.3.1             Guzzle promises library
guzzlehttp/psr7                                 1.4.2              PSR-7 message implementation that also provides common ut...
hudhaifas/silverstripe-frontend-fields          dev-master 9dc2020 Upload Image / File from Silverstripe frontend.
intervention/image                              2.4.2              Image handling and manipulation library with support for ...
jonom/focuspoint                                3.0.0              Smarter automatic image cropping for SilverStripe
league/csv                                      8.2.3              Csv data manipulation made easy in PHP
league/flysystem                                1.0.46             Filesystem abstraction: Many filesystems, one API.
m1/env                                          2.1.2              Env is a lightweight library bringing .env file parser co...
marcj/topsort                                   1.1.0              High-Performance TopSort/Dependency resolving algorithm
monolog/monolog                                 1.23.0             Sends your logs to files, sockets, inboxes, databases and...
myclabs/deep-copy                               1.7.0              Create deep copies (clones) of your objects
nikic/php-parser                                v3.1.5             A PHP parser written in PHP
paragonie/random_compat                         v2.0.17            PHP 5.x polyfill for random_bytes() and random_int() from...
pgrimaud/instagram-user-feed                    5.1.3              Easily fetch any user's Instagram feed without oAuth for PHP
phpdocumentor/reflection-common                 1.0.1              Common reflection classes used by phpdocumentor to reflec...
phpdocumentor/reflection-docblock               4.3.0              With this component, a library can provide support for an...
phpdocumentor/type-resolver                     0.4.0
phpspec/prophecy                                1.8.0              Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                       4.0.8              Library that provides collection, processing, and renderi...
phpunit/php-file-iterator                       1.4.5              FilterIterator implementation that filters files based on...
phpunit/php-text-template                       1.2.1              Simple template engine.
phpunit/php-timer                               1.0.9              Utility class for timing
phpunit/php-token-stream                        2.0.2              Wrapper around PHP's tokenizer extension.
phpunit/phpunit                                 5.7.27             The PHP Unit Testing framework.
phpunit/phpunit-mock-objects                    3.4.4              Mock Object library for PHPUnit
psr/cache                                       1.0.1              Common interface for caching libraries
psr/container                                   1.0.0              Common Container Interface (PHP FIG PSR-11)
psr/http-message                                1.0.1              Common interface for HTTP messages
psr/log                                         1.0.2              Common interface for logging libraries
psr/simple-cache                                1.0.1              Common interfaces for simple caching
ryanpotter/silverstripe-cms-theme               3.3.0              CMS Theme
sebastian/code-unit-reverse-lookup              1.0.1              Looks up which function or method a line of code belongs to
sebastian/comparator                            1.2.4              Provides the functionality to compare PHP values for equa...
sebastian/diff                                  1.4.3              Diff implementation
sebastian/environment                           2.0.0              Provides functionality to handle HHVM/PHP environments
sebastian/exporter                              2.0.0              Provides the functionality to export PHP variables for vi...
sebastian/global-state                          1.1.1              Snapshotting of global state
sebastian/object-enumerator                     2.0.1              Traverses array structures and object graphs to enumerate...
sebastian/recursion-context                     2.0.0              Provides functionality to recursively process PHP variables
sebastian/resource-operations                   1.0.0              Provides a list of PHP built-in functions that operate on...
sebastian/version                               2.0.1              Library that helps with managing the version number of Gi...
sheadawson/silverstripe-linkable                2.0.0              A couple of handy form fields and objects for managing ex...
silverstripe/admin                              1.2.1              SilverStripe admin interface
silverstripe/asset-admin                        1.2.1              Asset management for the SilverStripe CMS
silverstripe/assets                             1.2.1              SilverStripe Assets component
silverstripe/campaign-admin                     1.2.1              SilverStripe campaign admin interface
silverstripe/cms                                4.2.1              The SilverStripe Content Management System
silverstripe/config                             1.0.6              SilverStripe configuration based on YAML and class statics
silverstripe/errorpage                          1.2.1              ErrorPage component for SilverStripe CMS
silverstripe/framework                          4.2.1              The SilverStripe framework
silverstripe/googlesitemaps                     2.1.2              SilverStripe support for the Google Sitemaps XML, enablin...
silverstripe/graphql                            2.0.1              GraphQL server for SilverStripe models and other data
silverstripe/recipe-cms                         4.2.1              SilverStripe recipe for fully featured page and asset con...
silverstripe/recipe-core                        4.2.1              SilverStripe framework-only core recipe
silverstripe/recipe-plugin                      1.3.0              Helper plugin to install SilverStripe recipes
silverstripe/reports                            4.2.1              Reports module for SilverStripe CMS
silverstripe/segment-field                      2.2.1              A reusable approach to segment-generating fields
silverstripe/siteconfig                         4.2.1              Site wide settings administration.
silverstripe/spamprotection                     3.0.0              Spam protection module for SilverStripe.
silverstripe/userforms                          5.2.1              UserForms enables CMS users to create dynamic forms via a...
silverstripe/vendor-plugin                      1.3.3              Allows vendor modules to expose directories to the webroot
silverstripe/versioned                          1.2.1              SilverStripe Versioned component
silverware/calendar                             1.1.0              SilverWare Calendar Module.
silverware/countries                            1.0.2              SilverWare Countries Module.
silverware/select2                              1.2.0              SilverWare Select2 Module.
swiftmailer/swiftmailer                         v5.4.12            Swiftmailer, free feature-rich PHP mailer
symbiote/silverstripe-gridfieldextensions       3.2.0              A collection of useful grid field components
symfony/cache                                   v3.4.15            Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                                  v3.4.15            Symfony Config Component
symfony/filesystem                              v3.4.15            Symfony Filesystem Component
symfony/finder                                  v3.4.15            Symfony Finder Component
symfony/polyfill-apcu                           v1.9.0             Symfony polyfill backporting apcu_* functions to lower PH...
symfony/polyfill-ctype                          v1.9.0             Symfony polyfill for ctype functions
symfony/polyfill-mbstring                       v1.9.0             Symfony polyfill for the Mbstring extension
symfony/translation                             v2.8.45            Symfony Translation Component
symfony/yaml                                    v3.4.15            Symfony Yaml Component
tractorcow/silverstripe-colorpicker             4.0.0              Color picker field for Silverstripe CMS using the ColorPi...
unclecheese/betterbuttons                       dev-master bf31a8a Adds new form actions and buttons to GridField detail for...
unclecheese/display-logic                       2.0.1              Allows assignment of conditions for display and hide of s...
undefinedoffset/silverstripe-nocaptcha          2.0.0              A spam protector and form field using the new Google's re...
undefinedoffset/sortablegridfield               2.0.6              Adds drag and drop functionality to SilverStripe 4.x's Gr...
webmozart/assert                                1.3.0              Assertions to validate method input/output with nice erro...
webonyx/graphql-php                             v0.8.0             A PHP port of GraphQL reference implementation

Page.php

<?php

use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\File;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Forms\CheckboxField;

use App\Web\Banner;

class Page extends SiteTree
{

    private static $can_be_modal = true;

    private static $db = array(
        'Quicklink' => 'Boolean',
        'SidebarMenu' => 'Boolean'
    );

    private static $has_one = array(
        'Image' => Image::class
    );

    private static $many_many = array(
        'Files' => File::class
    );

    private static $owns = ['Image','Files'];

    public function onAfterWrite()
    {
        parent::onAfterWrite();

        // force republish of files to set sort order
        if ($this->Files()->exists()){
            foreach ($this->Files() as $file) {
                $file->publishSingle();
            }
        }
    }

    public function getCMSFields() {

        $fields = parent::getCMSFields();

        $fields->addFieldsToTab('Root.Attachments', [
            $filesuploader = UploadField::create('Files')
                ->setAllowedExtensions(['pdf','xls','xlsx','doc','docx'])
                ->setFolderName('Files')
        ]);
        $filesuploader->getValidator()->setAllowedMaxFileSize(2*1024*1024);

        if (!$this->hasMethod('banners')){
            $fields->addFieldsToTab('Root.Banner', array(
                $banneruploader = UploadField::create('Image','Banner')
                    ->setAllowedExtensions(['png','jpeg','jpg'])
                    ->setFolderName('Banners')
            ));
            $banneruploader->getValidator()->setAllowedMaxFileSize(2*1024*1024);
        }

        return $fields;
    }

    public function getSettingsFields() {
        $fields = parent::getSettingsFields();

        $fields->addFieldsToTab('Root.Settings', array(
            CheckboxField::create('Quicklink','Show in quicklinks?'),
            CheckboxField::create('SidebarMenu','Show sidebar menu?')
        ),
        'ShowInMenus');

        return $fields;
    }

    public function Quicklinks() {
        return Page::get()->filter('Quicklink',1)->Sort(['Sort'=>'DESC']);
    }

    // If the page does not have an image, and a default image is defined in SiteConfig, return that instead.
    public function Image()
    {
        $image = $this->getComponent('Image');
        $this->extend('updateImage', $image);

        if ($image && $image->exists() /*&& file_exists($image->getFullPath())*/) {
            return $image;
        }

        $image = SiteConfig::current_site_config()->DefaultBanner();
        if ($image && $image->exists() /*&& file_exists($image->getFullPath())*/) {
            return $image;
        }
        //return $this->model->Image->newObject();
    }

    // return files in sorted order
    public function getSortedFiles() {
        return $this->Files()->sort(['Title'=>'ASC']);
    }

}

ContactPage.php

namespace App\Web;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Control\UserDefinedFormController;

class ContactPage extends UserDefinedForm {
    private static $table_name = 'ContactPage';
}
class ContactPage_Controller extends UserDefinedFormController {
    public function init() {
        parent::init();
    }
}
robbieaverill commented 5 years ago

Web inspector shows: TypeError: $(this).button is not a function. (In '$(this).button('destroy')', '$(this).button' is undefined) in dropdown_form_action.js:47

Hi @elkebe, it looks like your error is caused by betterbuttons, might be worth bring up the issue over there. Thanks for raising it though.