salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.44k stars 2.07k forks source link

Validation js missing from extended bean editview template #10307

Closed gahenderson closed 8 months ago

gahenderson commented 8 months ago

Issue

When extending the OOTB Surveys module, the field validation on editview has stopped working for most or all fields. When checking the cached EditView template, none of the validation js has been added. This means that, for example, the mandatory 'name' field can be left blank, and the record saved.

Expected Behavior

The buildTemplate function of TemplateHandler should be able to correctly find the module name when building the cached editview tpl file, allowing the javascript object to be set up with the correct bean. This allows for all mandatory fields to be correctly validated on save.

Actual Behavior

The module name isn't correct (using the name of the extended bean, and not its core counterpart), so when javascript's addAllFields runs, it misses most or all of the fields to be validated. This results in missing javascript, preventing field validation on editview save.

Possible Fix

Use BeanFactory to get the module name, instead of looking it up in the BeanList global variable

Steps to Reproduce

  1. Extend the Surveys Bean through the code (e.g. in custom/Extension/application/Ext/Include directory)
    $objectList['Surveys'] = 'Surveys';
    $beanList['Surveys'] = 'CustomSurveys';
    $beanFiles['CustomSurveys'] = 'custom/modules/Surveys/Surveys.php';
  2. Delete the EditView.tpl from cache (if exists) cache/themes/SuiteP/modules/Surveys/EditView.tpl
  3. Repair & rebuild
  4. Navigate to surveys editview
  5. Save record without populating mandatory fields

Context

Prevents correct validation of a module which can be used to design customer-facing surveys, medium priority

Your Environment