Add new Item containing \\ and \ ( paths)

1 Answer 60 Views
MultiSelect
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Rob asked on 16 Jun 2022, 02:35 AM

I have a Grid, which has a column that uses a MultiSelect as an editor and also allows the user to add new items.  This is all running off a remote data with crud etc

It's been 4 days to get it all working.. lost a bit of hair , but finally it all works! ( all the examples just were not applicable or when used together caused issues!) 

It all looks good now, but  I have got 1 more bit to sort and I'm struggling to keep going . Would really appreciate a little help.

The Multi Select is for selecting Shares / Paths. This is find if they are already defined in the database, but I cannot add them using the Add New approach.
e.g the user types \\Server\Share as a new item.. and then try's to add it... we end up with \ServerShare

The issue is what I am getting back from  input.val 

<script id="noDataTemplate" type="text/x-kendo-tmpl">
    # var value = instance.input.val(); #
    # var id = instance.element[0].id; #
    <div>
        No data found. Do you want to add new item - '#= value #' ?
    </div>
    <br />
    <button class="k-button k-button-solid-base k-button-solid k-button-md k-rounded-md" onclick="addNew('#: id #', '#= value #')" ontouchend="addNew('#: id #', '#: value #')">Add new item</button>
</script>

I can't find a way to get a raw string of the  instance.input.val();

Any ideas greatly appreciated,

Many thanks

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 19 Jun 2022, 11:34 PM | edited on 19 Jun 2022, 11:35 PM

I solved this by using javascript to get the value , rather than inside the template itself.

Because I only have 1 multiselect on the page at any time ( because it's only used as the cell editor),  I am able to select the input by the classes and when using javascript to read the value, the backslashes are preserved.

I could have used the widgetId to try and be more selective, but in my case it was not needed.

    function addNew(widgetId, value) 

        var wrapper = document.getElementsByClassName("k-multiselect-wrap")[0];
        var thisinput = wrapper.getElementsByClassName("k-input")[0];
        value = thisinput.value;
Just a warning to anyone who maybe trying to do the same, this is from a version about 1 year old. The class names and even where the input is located in the structure has changed now..  which makes this approach prone to breaking with updates

but I thought it best I add an answer to my question 

Rob
Tags
MultiSelect
Asked by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or