Skip to content

Commit

Permalink
#26 Nefunkční Nette.initForm
Browse files Browse the repository at this point in the history
Ve vzácných případech mohlo dojít k situace, že Nette.initForm způsobila chybu v případě AJAXové validace. Výjimečně mohlo dojít k tomu, že JS událost DOMContentLoaded byla vyvolána dříve, než dojde ke zpracování již staženého JS. V tu chvíli event handler vyvolat inicializaci formuláře, která prostředníctvím Nette.toggleForm spustila AJAXovou validaci ve chvíli, kdy ještě $.nette bylo undefined.

Protože AJAXová validace vrací vždy `true`, není klíčové při `toggleForm` metodě vyvolávat request. Proto byla přidána podmínka, která ověřuje, že je `$.nette.ajax` definované.
  • Loading branch information
zipper committed Jan 21, 2020
1 parent 72c6c38 commit 8c43573
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pd-forms",
"title": "pdForms",
"description": "Customization of netteForms for use in PeckaDesign.",
"version": "3.0.3",
"version": "3.0.4",
"author": "PeckaDesign, s.r.o <support@peckadesign.cz>",
"contributors": [
"Radek Šerý <radek.sery@peckadesign.cz>",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/pdForms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @name pdForms
* @author Radek Šerý <radek.sery@peckadesign.cz>
* @version 3.0.3
* @version 3.0.4
*
* Features:
* - live validation
Expand Down Expand Up @@ -45,7 +45,7 @@

var pdForms = window.pdForms || {};

pdForms.version = '3.0.3';
pdForms.version = '3.0.4';


/**
Expand Down
6 changes: 6 additions & 0 deletions src/assets/validators/nette.ajax/pdForms.validator.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
(function() {

Nette.validators.PdFormsRules_ajax = function(elem, arg, val, value, callback) {
// In case of $.nette.ajax being undefined, do not validate. This may happen on page load when Nette.initForm
// is called.
if (! $ || ! $.nette || ! $.nette.ajax) {
return true;
}

if (typeof callback === 'undefined') {
callback = 'PdFormsRules_ajax';
}
Expand Down

0 comments on commit 8c43573

Please sign in to comment.