nuejs/nue

When '{}' or',' in html , How to escape?

yuhengliang opened this issue · 3 comments

<input type="text" name="captcha" value="" placeholder="" required pattern="^\d{4,5}$" />

When '{}' or',' in html , How to escape?

I thought, something like this pattern="{'^\d{4,5}$'}" or this :pattern="'^\d{4,5}$'" would work, but it seems, the shortest match of {} is taken resulting in pattern="{'^\d45$'}" and pattern="'^\d45$'" respectively

So you currently have to do for example something like the following:

<div>
  <p>e.g. a layout component or area or some other scope</p>
  <input type="text" name="captcha" value="" placeholder="" required :pattern />
  <!-- or -->
  <input type="text" name="captcha" value="" placeholder="" required :pattern="patternvar" />

  <script>
    pattern = '^\d{4,5}$'
    // or
    patternvar = 'some pattern'
  </script>
</div>

Hope that helps, at least until there is a proper fix :)

It's not the shortest match, but a match that does not contain { or }:

Related code:

str.split(EXPR).map((str, i) => {

const EXPR = /\{([^{}]+)\}/g


I wouldn't expect this to ever work like you expect it to (except maybe, when pattern is excluded from being parsed).
It is probably the easiest to just define a variable, that contains the pattern, and use the variable.