Null values on template

Hi,

We are making use of the template functionality for the listbox. One of our fields is a string & there's the possibility that the field will be null. When this renders it's printing the value "null". Is there a way to change this to rather print out an empty string?

    @Html.EJ().ListBox("images").Width("100%").Height("100%").Datasource(Model.Images).Template("<img class='eimg' src='../Images/GetImage?fileId=${Id}' Width='200px' Height='200px' /><textarea class='e-field' cols='30' rows='3' id='Description' name='Description' maxlength='500'>${Description}</textarea>")

Please advise 

3 Replies 1 reply marked as answer

MK Muthukrishnan Kandasamy Syncfusion Team August 12, 2020 12:57 PM UTC

 
Hi Malcolm, 
 
Thanks for contacting Syncfusion support. 
 
We have validated your requirement in EJ ListBox control. By default, if we assign the null value or any string value , the same will be rendered as content in ListBox template. For your requirement, we have overridden the default behavior if the field value is null, then we have assigned the empty string value. Please refer to the below code block. 
 
ej.ListBox.prototype._getTemplatedString = function (list) { 
            var str = this.model.template, 
                start = str.indexOf("${"), 
                end = str.indexOf("}"); 
            while (start != -1 && end != -1) { 
                var content = str.substring(startend + 1); 
                var field = content.replace("${""").replace("}"""); 
                var fldValue = this._getField(listfield); 
                iffldValue == "null" || fldValue == null){ 
                    str = str.replace(content""); 
                } else { 
                    str = str.replace(contentfldValue); 
                } 
                start = str.indexOf("${"), end = str.indexOf("}"); 
            } 
            return str; 
        } 
 
 
We have prepared a sample in JS Playground, please refer to the below link for the sample. 
 
 
 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Muthukrishnan K 
 


Marked as answer

MV Malcolm van Staden August 12, 2020 02:34 PM UTC

Thank you for the provided solution. 


MK Muthukrishnan Kandasamy Syncfusion Team August 13, 2020 04:41 AM UTC

Hi Malcolm, 
 
Welcome. Please, get back to us if you need any further assistance. We will be happy to assist you. 
 
Regards, 
Muthukrishnan K 


Loader.
Up arrow icon