Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make input form read-only?

I have a bunch of forms that have a lot of <input type="text"> fields on them. The user now is requiring that I provide a "read-only" version of every single form. I would recode every field into an

<xsl:choose>
<xsl:when test="/..../permission = 'E'>
  <input ....>
</xsl:when>
<xsl:otherwise>
  ...
</xsl:otherwise>
</xsl:choose>

mess, but I'm hoping for something a little more elegant. A friend suggested

  $(function () {
        <xsl:if test="/.../permission != 'E'">
            $('input').keypress(function() { return false; });
        </xsl:if>
    });

which does part of what I want, but you can still paste into the fields and you can still delete from them.

like image 817
Paul Tomblin Avatar asked Apr 14 '26 22:04

Paul Tomblin


1 Answers

Judging from the fact that you're using XSLT, I'd say you're outputting in one of the XHTML doctypes, so why not just make the input element you're creating have the disabled attribute?

<input type="..." disabled="disabled" />

You could do this immediately in XSLT. If you're using the same input all over the place just create a template for it and use <xsl:apply-template .../> inside the test.

Post-comment edit

Apparently there's a readonly attribute as well. Silly :)

<input type="..." readonly="readonly" />
like image 84
Denis 'Alpheus' Cahuk Avatar answered Apr 17 '26 11:04

Denis 'Alpheus' Cahuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!