Fixed form initialisation with empty model/attributes.
This commit is contained in:
parent
cca9740465
commit
34e92456f7
4 changed files with 28 additions and 12 deletions
|
@ -9,6 +9,11 @@ class App.ControllerForm extends App.Controller
|
|||
@handlers.push @showHideToggle
|
||||
@handlers.push @requiredMandantoryToggle
|
||||
|
||||
if !@model
|
||||
@model = {}
|
||||
if !@attributes
|
||||
@attributes = []
|
||||
|
||||
# set empty class attributes if needed
|
||||
if !@form
|
||||
@form = @formGen()
|
||||
|
@ -16,11 +21,6 @@ class App.ControllerForm extends App.Controller
|
|||
# add alert placeholder
|
||||
@form.prepend('<div class="alert alert--danger js-alert hide" role="alert"></div>')
|
||||
|
||||
if !@model
|
||||
@model = {}
|
||||
if !@attributes
|
||||
@attributes = []
|
||||
|
||||
# if element is given, prepend form to it
|
||||
if @el
|
||||
@el.prepend(@form)
|
||||
|
@ -46,7 +46,7 @@ class App.ControllerForm extends App.Controller
|
|||
html: =>
|
||||
@form.html()
|
||||
|
||||
formGen: ->
|
||||
formGen: =>
|
||||
App.Log.debug 'ControllerForm', 'formGen', @model.configure_attributes
|
||||
|
||||
# check if own fieldset should be generated
|
||||
|
@ -55,6 +55,8 @@ class App.ControllerForm extends App.Controller
|
|||
else
|
||||
fieldset = $('<fieldset></fieldset>')
|
||||
|
||||
return fieldset if _.isEmpty(@model)
|
||||
|
||||
# collect form attributes
|
||||
@attributes = []
|
||||
if @model.attributesGet
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AppVersionForNewMessages < ActiveRecord::Migration
|
||||
def up
|
||||
AppVersion.set(true)
|
||||
end
|
||||
end
|
|
@ -27,6 +27,7 @@ set new app version and if browser reload is required
|
|||
=end
|
||||
|
||||
def self.set(reload_required = false)
|
||||
return false if !Setting.find_by(name: 'app_version')
|
||||
version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
|
||||
Setting.set('app_version', version)
|
||||
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
|
||||
// form
|
||||
test( "form without @el", function() {
|
||||
var form = new App.ControllerForm()
|
||||
|
||||
equal($(form.html()).is('div'), true)
|
||||
equal($(form.html()).hasClass('alert'), true)
|
||||
equal($(form.html()).hasClass('hide'), true)
|
||||
|
||||
})
|
||||
test( "form elements check", function() {
|
||||
// deepEqual( item, test.value, 'group set/get tests' );
|
||||
$('#forms').append('<hr><h1>form elements check</h1><form id="form1"></form>')
|
||||
|
|
Loading…
Reference in a new issue