x-editable, how to show specific value when string is empty?
Asked Answered
A

3

5

I am trying to show a default value when a field is null or empty (string), and edit mode is disabled using x-editable. Using the attribute "data-value" works great when the field or string is null, for example:

<b><a id="location_name" data-type="text" data-title="Location name" data-placeholder="Location" data-emptytext="Location" data-value="Location">@Model.geoLocation.location_name</a></b> <br />

However, if the string is empty (but not null), the data-value will not show. I was wondering if there is a way to still show the default data-value if the string is empty (i.e., in addition to when it is null).

Almira answered 6/12, 2013 at 1:26 Comment(0)
C
8

This works for me:

<script type="text/javascript">
  $(document).ready(function() {
    $.fn.editable.defaults.mode = 'popup';     

    $('.confirm_assistance').editable({
        url: '<?php echo PATH; ?>controllers/administrator/insert/boardingListPax.php',
        emptytext: 'Text for empty/null value'
    });
});
</script>

The thing here is to use

        emptytext: 'Text for empty/null value'
Conjoin answered 14/5, 2014 at 19:3 Comment(0)
H
0

I am just using || inside the a tag.

<a href="#" editable-text="user.name">{{ user.name || 'empty' }}</a>
Hispanicize answered 17/8, 2015 at 19:8 Comment(0)
F
0

Also if you want to edit the emptytext all of the inputs you can do this.

$.fn.editable.defaults.emptytext = 'Text for empty/null value';

$.fn.editable.defaults.emptytext = '{{ 'Text for empty/null value' | trans | escape('js') }}';
Fennelly answered 26/10, 2023 at 13:18 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jumpy

© 2022 - 2024 — McMap. All rights reserved.