jquery - How to access value in data-attributein an x-editable context? -
this code triggers display of form multiple fields (a postal address), inline editing. want values (street_name
, , more ) data attributes in triggering element. code below doesn't this. if put string "broadway" display. possible in params
(see code).
the documentation contains example of form multiple fields values hardcoded.
using $(this).editable().attr('steet_name')
doesn't work in value
(undefined not function
)
how can values need data attributes of triggering element?
edit - i'm using js several different triggering elements, can't set var street_name = $("#letteraddress").data('street_name');
$('.editable-address').editable({ url: '/en/ajax/methods?method=normalize-address', mode:'inline', // here $(this).attr() doesn't work value : { street_name: $(this).attr('data-street') }, // here, $(this).attr() work params: function(params) { params.column = $(this).attr('data-column'); return params; } });
edit adding relevant html
<a id="letteraddress" href="#" class="editable-address editable-empty-address" data-column="ind_id" data-street_name="<?=$addresses[1]->street_name?>" data-street_nbr="<?=$addresses[1]->street_nbr?>" data-city="<?=$addresses[1]->city?>" data-zipcode="<?=$addresses[1]->zipcode?>" data-country="<?=$addresses[1]->country?>" > <?=$address?> </a>
edit: found own solution. wrapping editable()
code around click
event can assign data attribute values of clicked element variables available used in editable()
code. note editable('show')
@ end
$('.editable-address').click(function() { var street = $(this).attr('data-street_name') $(this).editable({ url: '/ajax/url', mode:'inline', value: { adr_street_name: street }, params: function(params) { return params; } }).editable('show'); })
if you're trying access "data-street" property of following tag, use data
function:
<a href="#" data-street="some street" data-zip-code="12345"> <script> var value = $(this).data('street'); var zip = $(this).data('zip-code'); </script>
edit: new markup
var col = $(this).data('column'); var street_name = $(this).data('street_name'); var street_nbr = $(this).data('street_nbr'); var city = $(this).data('city'); var zipcode = $(this).data('zipcode'); var country = $(this).data('country');
Comments
Post a Comment