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

ajaxSubmit in edit_many_script expects html back, but gets json #6250

Closed
nieuwenhuisen opened this issue Aug 3, 2020 · 2 comments
Closed

Comments

@nieuwenhuisen
Copy link
Contributor

Environment

Sonata packages

sonata-project/admin-bundle              dev-master 6205c9b dev-master 6205c9b The missing Symfony Admin Generator
sonata-project/block-bundle              4.2.0              4.2.0              Symfony SonataBlockBundle
sonata-project/cache                     2.0.1              2.0.1              Cache library
sonata-project/doctrine-extensions       1.8.0              1.8.0              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle dev-master d145254 dev-master 791cae8 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.3.0              2.3.0              Lightweight Exporter library
sonata-project/form-extensions           1.5.0              1.5.0              Symfony form extensions
sonata-project/twig-extensions           1.3.1              1.3.1              Sonata twig extensions

Symfony packages

symfony/amqp-messenger             v5.1.3  v5.1.3  Symfony AMQP extension Messenger Bridge
symfony/asset                      v4.4.11 v5.1.3  Symfony Asset Component
symfony/cache                      v4.4.11 v5.1.3  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.1.3  v2.1.3  Generic abstractions related to caching
symfony/config                     v4.4.11 v5.1.3  Symfony Config Component
symfony/console                    v4.4.11 v5.1.3  Symfony Console Component
symfony/debug                      v4.4.11 v4.4.11 Symfony Debug Component
symfony/dependency-injection       v4.4.11 v5.1.3  Symfony DependencyInjection Component
symfony/deprecation-contracts      v2.1.3  v2.1.3  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v4.4.11 v5.1.3  Symfony Doctrine Bridge
symfony/doctrine-messenger         v5.1.3  v5.1.3  Symfony Doctrine Messenger Bridge
symfony/error-handler              v4.4.11 v5.1.3  Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.11 v5.1.3  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.9  v2.1.3  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.11 v5.1.3  Symfony ExpressionLanguage Component
symfony/filesystem                 v5.1.3  v5.1.3  Symfony Filesystem Component
symfony/finder                     v4.4.11 v5.1.3  Symfony Finder Component
symfony/form                       v4.4.11 v5.1.3  Symfony Form Component
symfony/framework-bundle           v4.4.11 v5.1.3  Symfony FrameworkBundle
symfony/http-foundation            v4.4.11 v5.1.3  Symfony HttpFoundation Component
symfony/http-kernel                v4.4.11 v5.1.3  Symfony HttpKernel Component
symfony/inflector                  v5.1.3  v5.1.3  Symfony Inflector Component
symfony/intl                       v5.1.3  v5.1.3  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle               v1.20.0 v1.20.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/messenger                  v5.1.3  v5.1.3  Symfony Messenger Component
symfony/mime                       v5.1.3  v5.1.3  A library to manipulate MIME messages
symfony/monolog-bridge             v5.1.3  v5.1.3  Symfony Monolog Bridge
symfony/monolog-bundle             v3.5.0  v3.5.0  Symfony MonologBundle
symfony/options-resolver           v4.4.11 v5.1.3  Symfony OptionsResolver Component
symfony/orm-pack                   v1.0.8  v2.0.0  A pack for the Doctrine ORM
symfony/phpunit-bridge             v4.4.11 v5.1.3  Symfony PHPUnit Bridge
symfony/polyfill-ctype             v1.18.0 v1.18.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme     v1.18.0 v1.18.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.18.0 v1.18.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.18.0 v1.18.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.18.0 v1.18.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.18.0 v1.18.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php70             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                    v5.1.3  v5.1.3  Symfony Process Component
symfony/profiler-pack              v1.0.4  v1.0.4  A pack for the Symfony web profiler
symfony/property-access            v4.4.11 v5.1.3  Symfony PropertyAccess Component
symfony/redis-messenger            v5.1.3  v5.1.3  Symfony Redis extension Messenger Bridge
symfony/routing                    v4.4.11 v5.1.3  Symfony Routing Component
symfony/security-acl               v3.0.4  v3.0.4  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.11 v5.1.3  Symfony SecurityBundle
symfony/security-core              v4.4.11 v5.1.3  Symfony Security Component - Core Library
symfony/security-csrf              v4.4.11 v5.1.3  Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.11 v5.1.3  Symfony Security Component - Guard
symfony/security-http              v4.4.11 v5.1.3  Symfony Security Component - HTTP Integration
symfony/service-contracts          v2.1.3  v2.1.3  Generic abstractions related to writing services
symfony/stopwatch                  v5.1.3  v5.1.3  Symfony Stopwatch Component
symfony/string                     v5.1.3  v5.1.3  Symfony String component
symfony/templating                 v4.4.11 v5.1.3  Symfony Templating Component
symfony/translation                v4.4.11 v5.1.3  Symfony Translation Component
symfony/translation-contracts      v2.1.3  v2.1.3  Generic abstractions related to translation
symfony/twig-bridge                v4.4.11 v5.1.3  Symfony Twig Bridge
symfony/twig-bundle                v4.4.11 v5.1.3  Symfony TwigBundle
symfony/validator                  v4.4.11 v5.1.3  Symfony Validator Component
symfony/var-dumper                 v5.1.3  v5.1.3  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v5.1.3  v5.1.3  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle        v5.0.11 v5.1.3  Symfony WebProfilerBundle
symfony/yaml                       v4.4.11 v5.1.3  Symfony Yaml Component

PHP version

7.3.18

Subject

.ajaxSubmit in edit_many_script expects html back, but gets json.
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/Association/edit_many_script.html.twig#L335

This is caused after a PR of me https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L1567 to add the wildcard accept header. Now the early return with the deprecation message not happen any more.

I want to make a PR to fix this, but I want to discuss how we could solve this. I am thinking of an extra json property with the html. For example:

{"result":"error", "errors":["Deze waarde mag niet leeg zijn."], "html": "<form ...>...</from>"}

Steps to reproduce

  1. Create a ModelType or ModelListType field.
  2. Click on "add" and submit an invalid form.

Expected results

<form
   class="form-horizontal"              role="form"
   action="/form_model_child/create?uniqid=s5f27fa0e8fe91"
   method="POST"
   novalidate="novalidate"                            >
   <div class="row">
      <div class="col-md-12">
         <div class="row">
            <div class="col-md-12">
               <div class="box box-primary">
                  <div class="box-header">
                     <h4 class="box-title">
                        Form model child
                     </h4>
                  </div>
                  <div class="box-body">
                     <div class="sonata-ba-collapsed-fields">
                        <div class="form-group has-error" id="sonata-ba-field-container-s5f27fa0e8fe91_title">
                           <label class="col-sm-3 control-label required" for="s5f27fa0e8fe91_title">
                           Title
                           </label>
                           <div class="sonata-ba-field col-sm-9 sonata-ba-field-standard-natural sonata-ba-field-error">
                              <input type="text" id="s5f27fa0e8fe91_title" name="s5f27fa0e8fe91[title]" required="required" class=" form-control" />
                              <div class="help-block sonata-ba-field-error-messages">
                                 <ul class="list-unstyled">
                                    <li><i class="fa fa-exclamation-circle" aria-hidden="true"></i> Deze waarde mag niet leeg zijn.</li>
                                 </ul>
                              </div>
                              <span class="help-block sonata-ba-field-widget-help sonata-ba-field-help"></span>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
   <input type="hidden" id="s5f27fa0e8fe91__token" name="s5f27fa0e8fe91[_token]" class=" form-control" value="Du8ITiMsSkEajWSCmQX9L0pp7tiSaODpsUSPkjtLecc" />
   <div class="sonata-ba-form-actions well well-small form-actions">
      <button type="submit" class="btn btn-success" name="btn_create"><i class="fa fa-plus-circle" aria-hidden="true"></i> Aanmaken</button>
   </div>
</form>

Actual results

{"result":"error","errors":["Deze waarde mag niet leeg zijn."]}
@VincentLanglet
Copy link
Member

Fix by #6222

@tifabien
Copy link
Contributor

Fixed more by #6889 :)

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

3 participants