How do I use X-editable on dynamic fields in a Meteor template now with Blaze?

前端 未结 6 2066
忘了有多久
忘了有多久 2021-01-01 05:42

I had x-editable working in Meteor 0.7.2 but since upgrading to 0.8.0 it no longer renders correctly. I tend to end up with a bunch of Empty tags. This is frustrating becaus

6条回答
  •  孤城傲影
    2021-01-01 06:09

    Yet another implementation working with iron-router and managing Collection2 validation:

    The control

    div(id="text" class="editable" data-type="text" data-pk="#{_id}" data-name="address" data-value="#{address}" data-context="Buildings") #{address}
    

    And the JS code:

      setTimeout( ->   #needed to work with iron-router
        $(".editable").editable
          placement: "auto top"
          display: ->
          success: (response, newValue) ->
            newVal = {}
            oldVal = $.trim $(this).data("value")
            name = $(this).data("name")
            newVal[name] = newValue
            eval($(this).data("context")).update $(this).data("pk"), $set: newVal
            , (error) ->
              Notifications.error error.message
              Meteor.defer -> $(".editable[data-name=" + name + "]").data('editableContainer').formOptions.value = oldVal
    
            console.log "set new value to " + newValue
            Session.set "text", newValue
      ,500)
    

    I couldn't find a way to set the data context automatically. I'm sure it shouldn't be very difficult. Any help welcome!

提交回复
热议问题