Author Topic: Html characters in cell value  (Read 4941 times)

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Html characters in cell value
« on: July 24, 2014, 02:36:03 am »
Hi,

Is there a way to easily remove html characters when retrieving $( "#grid_array" ).pqGrid( "option" , "dataModel.data" )?

I put it into javascript variable and send it to PHP server side, where the problem occurs. (the way data is accessed: $dataArray[$i][0] )

Thanks!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Html characters in cell value
« Reply #1 on: July 24, 2014, 04:33:54 pm »
there is no inbuilt method in pqgrid to remove HTML characters, you could take the help of this post.

http://stackoverflow.com/questions/822452/strip-html-from-text-javascript

I would also suggest to avoid HTML characters in grid data in the first place. dataModel.data should contain pure data and any HTML formatting should be done in column.render callback.
« Last Edit: July 24, 2014, 05:00:37 pm by paramquery »

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Html characters in cell value
« Reply #2 on: July 24, 2014, 07:47:10 pm »
The problem is -- I do not put any html chars in the cells, a user just puts in some text, and sometimes <br> comes up or <span class="...">...</span> as a value. So my questions was how to avoid it?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Html characters in cell value
« Reply #3 on: July 24, 2014, 08:03:30 pm »
What is the type of editor you are using?

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Html characters in cell value
« Reply #4 on: July 24, 2014, 08:27:07 pm »
editModel: {clicksToEdit: 1, saveKey: 13},

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Html characters in cell value
« Reply #5 on: July 25, 2014, 12:57:31 pm »
you haven't mentioned what kind of editor you are using.

If it's contenteditable, then any line break in text would appear as <br/> in the data.

If it's textbox or textarea, there won't be any HTML characters unless the user types raw HTML i.e., <br/>, <span> deliberately.

In any case you can clean the input before accepting it in data by implementing editor.getData callback.

As an example:

                editor: {
                    type: "textarea",
                    attr: "rows=3",
                    getData: function (ui) {
                        //debugger;
                        var tmp = document.createElement("DIV");
                        tmp.innerHTML = ui.$cell.find(".pq-editor-focus").val();
                        return tmp.textContent || tmp.innerText || "";
                    }
                }

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Html characters in cell value
« Reply #6 on: July 25, 2014, 07:53:07 pm »
I'm not specifying any "editor", based on assumption that there is a default one. Is the default editor not "textarea"?
Do I have to specify editor in each grid to solve the problem?