- Jump To … +
  /home/thiago/workspace-tapestry/tapestry-5/tapestry-beanvalidator/src/main/coffeescript/META-INF/modules/t5/beanvalidator/beanvalidator-validation.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/build/postprocessed-coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/build/postprocessed-coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/ajax.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/ajaxformloop.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/alert.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/autocomplete.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/bootstrap.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/confirm-click.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/console.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/datefield.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/exception-display.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/exception-frame.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/init.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/messages.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/moment.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/pageinit.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/select.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/time-interval.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/tree.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone-refresh.coffee /home/thiago/workspace-tapestry/tapestry-5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee

- # form-fragment.coffee

- ¶

  Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

      http:#www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

- ¶

  ## t5/core/form-fragment

      define ["underscore", "./dom", "./events", "./forms"],
        (_, dom, events) ->

          SELECTOR = "[data-component-type='core/FormFragment']"

          REENABLE = "data-re-enable-when-fragment-visible"

          disableInputFields = (fragment) ->

- ¶

  This is an example of where the t5/core/dom abstraction label is problematic, as this is very inefficient vs. the native jQuery approach.

            for field in fragment.find "input:not(:disabled)"
              field.attr "disabled", true
              field.attr REENABLE, true

          renableInputFields = (fragment) ->

            for field in fragment.find "input[#{REENABLE}]"
              field.attr "disabled", null
              field.attr REENABLE, null

          updateFields = (fragment, makeVisible) ->

- ¶

  This is a server side option that says the content of the fragment should always be submitted, even if the fragment is not currently visible.

            return if fragment.attr "data-always-submit"

            f = if makeVisible then renableInputFields else disableInputFields

            f fragment

- ¶

  Again, a DOM event to make the FormFragment visible or invisible; this is useful because of the didShow/didHide events … but we’re really just seeing the evolution from the old style (the FormFragment class as controller) to the new style (DOM events and top-level event handlers).

          dom.onDocument events.formfragment.changeVisibility, SELECTOR, (event) ->
              makeVisible = event.memo.visible

              this[if makeVisible then "show" else "hide"]()

              updateFields this, makeVisible

              @trigger events.element[if makeVisible then "didShow" else "didHide"]

              return false

- ¶

  When a FormFragment is initially rendered as hidden, then we need to do some book-keeping on the client side.

          hide = (id) ->
            field = dom(id)

            updateFields field, false

- ¶

  Initializes a trigger for a FormFragment

  - spec.triggerId - id of checkbox or radio button
  - spec.fragmentId - id of FormFragment element
  - spec.invert - (optional) if true, then checked trigger hides (not shows) the fragment

          linkTrigger = (spec) ->
            unless spec.triggerId? then throw new Error "Incomplete parameters, triggerId is null"
            unless spec.fragmentId? then throw new Error "Incomplete parameters, fragmentId is null"
            trigger = dom spec.triggerId
            fragment = dom spec.fragmentId
            if fragment is null
              throw new Error "Invalid configuration, fragment with id #{spec.fragmentId} not found"

            invert = spec.invert or false

            update = ->
              checked = trigger.element.checked
              makeVisible = checked isnt invert

              fragment.trigger events.formfragment.changeVisibility,  visible: makeVisible

              return

            if trigger.element.type is "radio"
              dom.on trigger.element.form, "click", update
            else
              trigger.on "click", update

- ¶

  Module exports:

          { linkTrigger, hide }