Why does contenteditable="false" not work?

40 views Asked by At

I have a C.R.U.D. app that builds many columns using PHP like this one below. This one is not meant to be editable by the user, only allowing a left click to display a dialogbox and a right click to run the function you see. The issue is the field always opens allowing an entry, how do I prevent that, why is contenteditable="false" not preventing it? I need it to act more like a button than an editable field, but a button would be hard to fit in with the rest of the fields which are editable. New edit: I tried using 'readonly' that prevented the from opening but it also stopped both click events. I'm open to a redesign on the entire td but I need suggestions on how and what.

<?php
Echo ("
...
<td $brbCols contenteditable=\"false\"
   class=\" W3W  c24 cent\" 
   id=\"w3w:$row[recordID]\" 
   oncontextmenu=\"mapWhat3Words('$row[w3w]');return false; \" 
   onClick=\"empty('w3w:$row[recordID]'); getAPRSLocations('$row[aprs_call], $row[recordID], $row[latitude],$row[longitude],$row[callsign],$row[netID], W3W');\" 
   style=\"cursor: pointer;\">
   <div class='$class' readonly> $row[w3w]  </div> 
</td> 
...
");
?>

I've tried using CSS and later JavaScript to add the contenteditable="false" after the field is created, but it too didn't work. I've tested the issue in Safari, FireFox and Chrome they all behave the same way.

1

There are 1 answers

3
nithinks On

The contenteditable attribute is used to make elements editable, but setting it to "false" might not prevent focus and editing. To prevent editing, try using the readonly attribute.

<?php
echo ("
...
<td $brbCols readonly
   class=\" W3W  c24 cent\" 
   id=\"w3w:$row[recordID]\" 
   oncontextmenu=\"mapWhat3Words('$row[w3w]');return false; \" 
   onClick=\"empty('w3w:$row[recordID]'); getAPRSLocations('$row[aprs_call], $row[recordID], $row[latitude],$row[longitude],$row[callsign],$row[netID], W3W');\" 
   style=\"cursor: pointer;\">
   <div class='$class'> $row[w3w] </div> 
</td> 
...
");
?>