Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Input required... WITH rendered output #461

Open
BrentH-Alnico opened this issue Oct 12, 2024 · 3 comments
Open

<Input required... WITH rendered output #461

BrentH-Alnico opened this issue Oct 12, 2024 · 3 comments

Comments

@BrentH-Alnico
Copy link

Hi Boris,

I haphazardly discovered a minor issue:

I normally use required like this...
<input type="checkbox" value="{{:value}}" data-link="required{:value == 0}" />

But I forgot and used it like this...
<input type="checkbox" value="{{:value}}" data-link="required{:value == 1 ? true : false}" />
or this
<input type="checkbox" value="{{:value}}" data-link="required{:value == 1 ? 'required' : ''}" />
neither of which works.

Testing: I changed required to disabled and it did work strangely...

I looked at the JsViews source code and added attr === "required" to line 4797
else if (attr === "selected" || attr === "disabled" || attr === "multiple" || attr === "readonly" || attr === "required")

This fixed it and makes it consistent with how disabled works too ;-)

Brent

@BorisMoore
Copy link
Owner

Thanks Brent - I agree, that fix is appropriate.

I tested the following:

{^{on ~flipInteger/}} {^{:integer}} <br/>

<input type="checkbox" data-link="bool"> FlipBool {^{:bool}}<br/><br/>

<form>

  <button type="submit">Submit Changes</button><br/><br/>

  Requires fix
  <input type="checkbox" value="{{:value}}" data-link="required{:integer ? 'required' : ''}" /> 

  Requires fix
  <input type="checkbox" value="{{:value}}" data-link="required{:integer}" /> 

  Requires fix
  <input type="checkbox" value="{{:value}}" data-link="required{:bool == true ? 'required' : ''}" /> 

  Requires fix
  <input type="checkbox" value="{{:value}}" data-link="required{:bool ? 'required' : ''}" /> 

  Works without fix
  <input type="checkbox" value="{{:value}}" data-link="required{:integer==1}" />

  Works without fix
  <input type="checkbox" value="{{:value}}" data-link="required{:bool}" />

  Works without fix
  <input type="checkbox" value="{{:value}}" data-link="required{:bool == true}" />

</form>

With this code:

var tmpl = $.templates("#personTmpl");

var person = {
  integer: 0,
  bool: false
};

var helpers = {
  flipInteger: function() {
    $.observable(person).setProperty("integer", person.integer == 1 ? 0 : 1);
  }
}

tmpl.link("#result", person, helpers);

That said, I'm not sure whether to publish a new update based on this issue alone. We can see if any future issues come up that we want to publish fixes for (that we might then combine with this one).

But it's great that you identified this issue and associated fix...!

@BrentH-Alnico
Copy link
Author

Yeah, it is so minor...I would wait. Thanks

@BorisMoore
Copy link
Owner

BorisMoore commented Dec 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants