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

'onError' breaks 'for' tag with external template and passing parameters #354

Closed
trueqbit opened this issue Dec 3, 2016 · 3 comments
Closed

Comments

@trueqbit
Copy link

trueqbit commented Dec 3, 2016

I am trying to link a list of items to table-rows. There are two lists for different purposes, but with the exact same data structure, which is why I want to encapsulate markup for an item into an external template.

The list might be absent from the data, that's why I am using an onError handler. This is even more necessary because the list in turn is wrapped inside another optional container [note that the json is actually produced by x2js from xml].

Here is some simplified code to show what I am talking about:

var model = {
  persons: {
    /*person: [
      { name: 'name 1' },
    ]*/
  },
};

{^{for model.persons^person ~prefix='td' tmpl='#rowPartial' onError='fallback'/}}

The actual problem that occurs is that jsviews outputs 'fallback' instead of rendering the template.

Fixing the data structure, such that the 'persons' container is always present, is a possibility, but I believe this to be a bug in jsviews, because either removing 'onError' or the '~prefix' parameter makes things work again.

Here is a fiddle showcasing the issue.

@BorisMoore
Copy link
Owner

Thanks for finding this! Yes, it is a bug.

The fix is very simple. Change line https://github.com/BorisMoore/jsviews/blob/master/jsviews.js#L3620 to

sourceValue = linkFn(source, view, $sub);

I'll include the fix in the next update.

@trueqbit
Copy link
Author

trueqbit commented Dec 4, 2016

Thanks! The fix is working great, both for data-linked tags and elements.

trueqbit pushed a commit to trueqbit/jsviews that referenced this issue Jan 2, 2017
BorisMoore added a commit to BorisMoore/jsviews.com that referenced this issue Mar 9, 2017
Feature improvements:

- Major update for custom tags - including support for two-way binding to multiple
  args and props

  See samples: http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@jsv-draggable
  and tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=f46a512b
  and also jQuery UI tag control samples such as http://www.jsviews.com/#samples/tag-controls/jqui/resizable
  and http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable.
  Also many code examples in
  https://www.jsviews.com/download/sample-tag-controls/jsviews-jqueryui-widgets.js

  A tag definition can include:
    tag.bindTo - which specifies two-way bound parameters (one or more args and/or
      props)
    tag.linkedElement - which specifies selectors for linkedElems for any of the
      two-way bound parameters
    tag.linkedCtxParam - which specifies/names tag contextual parameters for any of
      the two-way bound parameters
    mainElement - which specifies selector for an element used for setting id, width
      or height (otherwise, linkedElem is used)

  A tag onBind event can set:
    tag.linkedElem
    tag.linkedElems
    tag.mainElem - which is the element used for setting id, width or height
      (otherwise, linkedElem is used)
    tag.displayElem - which is the element used for setting class (otherwise,
      mainElem/linkedElem is used)

  The following tag methods are available:
    tag.bndArgs() -  which returns array of 'external' bound parameters (after
      convert, if convert=... is specified)
    tag.update(...) - which observably updates any ('external') bound parameters
      (using convertBack, if specified)
    tag.setValue(...) - which sets tag itself to new ('internal') values of bound
      parameters
    tag.getValue(...) - which returns array of current ('internal') values of bound
      parameters

  New 'tag contextual parameters' feature - see samples and explanation:
    http://www.jsviews.com/#samples/tag-controls/jqui/resizable and
    http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@tag-ctxl-params

- Other custom tag improvements:

  New 'tag boundProps' feature:
    Tag definition can include: tag.boundProps - which specifies any additional props
      that are bound, without needing ^myprop=... notation. See sample:
      http://www.jsviews.com/#samples/tag-controls/range

  New 'tag contentCtx' feature:
    Tag definition can include: tag.contentCtx - which specifies the data context within
      the tag block content.
    Set contentCtx = true for inheriting parentView context, or to a function, for
      specifying other context

  New 'tag argDefault' feature:
    Tag definition can include: tag.argDefault: false - which prevents the first arg
      defaulting to current data

  New 'tag onUpdate: false' feature:
    Tag definition can include: tag.onUpdate: false - which is equivalent to an onUpdate
      handler which does nothing but returns false, so tag does not rerender when bound
      args or props update

- Major update for jQuery UI widget-based tag controls library:

  Extensive new jQueryUI widget controls support and accompanying samples/documentation:
  http://www.jsviews.com/#download/jqueryui-tagcontrols
  http://www.jsviews.com/#samples/tag-controls/jqui

- New lateRender=true feature: set lateRender=true on any tag, to make the tag render only
  after completing the data-linking pass. Useful for using expressions such as
  #childTags('myTag') in data-link expressions.
  See tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=6be4ff95
  and sample: http://www.jsviews.com/#samples/tag-controls/jqui/selectable@late-render

- {^{on ...}} with no content allows setting width, height, id and class

Perf improvements for sorting, moving, refreshing:

- Much improved perf for {^{for myArray}}...{{/for}} when making observable changes to
  underlying array. When using $.observable(myArray).refresh(...) or
  $.observable(myArray).move(...), the resulting changes to the rendered items no longer
  result in deleting and re-rendering the moved items. Instead the rendered HTML elements
  are simply moved to their new positions under the parent element.

Bug fixes:

- BorisMoore/jsviews#361: Breaking change (radiobuttons) - both
  radiogroup and directly data-linked radio buttons now behave identically. Neither of
  them coerce value to string
- Bug with setting tag.depends=... (Breaking change: Note that setting fn.depends="myArray"
  updates for array changes as well as prop change. See:
  http://www.jsviews.com/test/unit-tests-jsviews.html?testId=303f5bfd
- BorisMoore/jsviews#354: Minor 'onError' bug
- BorisMoore/jsviews#360: Datepicker bug fix for correct behavior
  when data-linking to a value of type Date
- Several minor bug fixes

Unit tests:

- Several additional unit tests

Other minor breaking changes:

- The undocumented lazyLink feature has been removed
- The undocumented init: false feature for custom tags has been removed.
BorisMoore added a commit to BorisMoore/jsviews.com that referenced this issue Mar 9, 2017
Feature improvements:

- Major update for custom tags - including support for two-way binding to multiple
  args and props

  See samples: http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@jsv-draggable
  and tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=f46a512b
  and also jQuery UI tag control samples such as http://www.jsviews.com/#samples/tag-controls/jqui/resizable
  and http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable.
  Also many code examples in
  https://www.jsviews.com/download/sample-tag-controls/jsviews-jqueryui-widgets.js

  A tag definition can include:
    tag.bindTo - which specifies two-way bound parameters (one or more args and/or
      props)
    tag.linkedElement - which specifies selectors for linkedElems for any of the
      two-way bound parameters
    tag.linkedCtxParam - which specifies/names tag contextual parameters for any of
      the two-way bound parameters
    mainElement - which specifies selector for an element used for setting id, width
      or height (otherwise, linkedElem is used)

  A tag onBind event can set:
    tag.linkedElem
    tag.linkedElems
    tag.mainElem - which is the element used for setting id, width or height
      (otherwise, linkedElem is used)
    tag.displayElem - which is the element used for setting class (otherwise,
      mainElem/linkedElem is used)

  The following tag methods are available:
    tag.bndArgs() -  which returns array of 'external' bound parameters (after
      convert, if convert=... is specified)
    tag.update(...) - which observably updates any ('external') bound parameters
      (using convertBack, if specified)
    tag.setValue(...) - which sets tag itself to new ('internal') values of bound
      parameters
    tag.getValue(...) - which returns array of current ('internal') values of bound
      parameters

  New 'tag contextual parameters' feature - see samples and explanation:
    http://www.jsviews.com/#samples/tag-controls/jqui/resizable and
    http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@tag-ctxl-params

- Other custom tag improvements:

  New 'tag boundProps' feature:
    Tag definition can include: tag.boundProps - which specifies any additional props
      that are bound, without needing ^myprop=... notation. See sample:
      http://www.jsviews.com/#samples/tag-controls/range

  New 'tag contentCtx' feature:
    Tag definition can include: tag.contentCtx - which specifies the data context within
      the tag block content.
    Set contentCtx = true for inheriting parentView context, or to a function, for
      specifying other context

  New 'tag argDefault' feature:
    Tag definition can include: tag.argDefault: false - which prevents the first arg
      defaulting to current data

  New 'tag onUpdate: false' feature:
    Tag definition can include: tag.onUpdate: false - which is equivalent to an onUpdate
      handler which does nothing but returns false, so tag does not rerender when bound
      args or props update

- Major update for jQuery UI widget-based tag controls library:

  Extensive new jQueryUI widget controls support and accompanying samples/documentation:
  http://www.jsviews.com/#download/jqueryui-tagcontrols
  http://www.jsviews.com/#samples/tag-controls/jqui

- New lateRender=true feature: set lateRender=true on any tag, to make the tag render only
  after completing the data-linking pass. Useful for using expressions such as
  #childTags('myTag') in data-link expressions.
  See tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=6be4ff95
  and sample: http://www.jsviews.com/#samples/tag-controls/jqui/selectable@late-render

- {^{on ...}} with no content allows setting width, height, id and class

Perf improvements for sorting, moving, refreshing:

- Much improved perf for {^{for myArray}}...{{/for}} when making observable changes to
  underlying array. When using $.observable(myArray).refresh(...) or
  $.observable(myArray).move(...), the resulting changes to the rendered items no longer
  result in deleting and re-rendering the moved items. Instead the rendered HTML elements
  are simply moved to their new positions under the parent element.

Bug fixes:

- BorisMoore/jsviews#361: Breaking change (radiobuttons) - both
  radiogroup and directly data-linked radio buttons now behave identically. Neither of
  them coerce value to string
- Bug with setting tag.depends=... (Breaking change: Note that setting fn.depends="myArray"
  updates for array changes as well as prop change. See:
  http://www.jsviews.com/test/unit-tests-jsviews.html?testId=303f5bfd
- BorisMoore/jsviews#354: Minor 'onError' bug
- BorisMoore/jsviews#360: Datepicker bug fix for correct behavior
  when data-linking to a value of type Date
- Several minor bug fixes

Unit tests:

- Several additional unit tests

Other minor breaking changes:

- The undocumented lazyLink feature has been removed
- The undocumented init: false feature for custom tags has been removed.
BorisMoore added a commit that referenced this issue Mar 9, 2017
Feature improvements:

- Major update for custom tags - including support for two-way binding to multiple
  args and props

  See samples: http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@jsv-draggable
  and tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=f46a512b
  and also jQuery UI tag control samples such as http://www.jsviews.com/#samples/tag-controls/jqui/resizable
  and http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable.
  Also many code examples in
  https://www.jsviews.com/download/sample-tag-controls/jsviews-jqueryui-widgets.js

  A tag definition can include:
    tag.bindTo - which specifies two-way bound parameters (one or more args and/or
      props)
    tag.linkedElement - which specifies selectors for linkedElems for any of the
      two-way bound parameters
    tag.linkedCtxParam - which specifies/names tag contextual parameters for any of
      the two-way bound parameters
    mainElement - which specifies selector for an element used for setting id, width
      or height (otherwise, linkedElem is used)

  A tag onBind event can set:
    tag.linkedElem
    tag.linkedElems
    tag.mainElem - which is the element used for setting id, width or height
      (otherwise, linkedElem is used)
    tag.displayElem - which is the element used for setting class (otherwise,
      mainElem/linkedElem is used)

  The following tag methods are available:
    tag.bndArgs() -  which returns array of 'external' bound parameters (after
      convert, if convert=... is specified)
    tag.update(...) - which observably updates any ('external') bound parameters
      (using convertBack, if specified)
    tag.setValue(...) - which sets tag itself to new ('internal') values of bound
      parameters
    tag.getValue(...) - which returns array of current ('internal') values of bound
      parameters

  New 'tag contextual parameters' feature - see samples and explanation:
    http://www.jsviews.com/#samples/tag-controls/jqui/resizable and
    http://www.jsviews.com/#samples/tag-controls/jqui/draggable-droppable@tag-ctxl-params

- Other custom tag improvements:

  New 'tag boundProps' feature:
    Tag definition can include: tag.boundProps - which specifies any additional props
      that are bound, without needing ^myprop=... notation. See sample:
      http://www.jsviews.com/#samples/tag-controls/range

  New 'tag contentCtx' feature:
    Tag definition can include: tag.contentCtx - which specifies the data context within
      the tag block content.
    Set contentCtx = true for inheriting parentView context, or to a function, for
      specifying other context

  New 'tag argDefault' feature:
    Tag definition can include: tag.argDefault: false - which prevents the first arg
      defaulting to current data

  New 'tag onUpdate: false' feature:
    Tag definition can include: tag.onUpdate: false - which is equivalent to an onUpdate
      handler which does nothing but returns false, so tag does not rerender when bound
      args or props update

- Major update for jQuery UI widget-based tag controls library:

  Extensive new jQueryUI widget controls support and accompanying samples/documentation:
  http://www.jsviews.com/#download/jqueryui-tagcontrols
  http://www.jsviews.com/#samples/tag-controls/jqui

- New lateRender=true feature: set lateRender=true on any tag, to make the tag render only
  after completing the data-linking pass. Useful for using expressions such as
  #childTags('myTag') in data-link expressions.
  See tests: http://www.jsviews.com/test/unit-tests-jsviews.html?testId=6be4ff95
  and sample: http://www.jsviews.com/#samples/tag-controls/jqui/selectable@late-render

- {^{on ...}} with no content allows setting width, height, id and class

Perf improvements for sorting, moving, refreshing:

- Much improved perf for {^{for myArray}}...{{/for}} when making observable changes to
  underlying array. When using $.observable(myArray).refresh(...) or
  $.observable(myArray).move(...), the resulting changes to the rendered items no longer
  result in deleting and re-rendering the moved items. Instead the rendered HTML elements
  are simply moved to their new positions under the parent element.

Bug fixes:

- #361: Breaking change (radiobuttons) - both
  radiogroup and directly data-linked radio buttons now behave identically. Neither of
  them coerce value to string
- Bug with setting tag.depends=... (Breaking change: Note that setting fn.depends="myArray"
  updates for array changes as well as prop change. See:
  http://www.jsviews.com/test/unit-tests-jsviews.html?testId=303f5bfd
- #354: Minor 'onError' bug
- #360: Datepicker bug fix for correct behavior
  when data-linking to a value of type Date
- Several minor bug fixes

Unit tests:

- Several additional unit tests

Other minor breaking changes:

- The undocumented lazyLink feature has been removed
- The undocumented init: false feature for custom tags has been removed.
@BorisMoore
Copy link
Owner

Fixed with commit 84

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

2 participants