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

Checkboxgroup issue when used with View Model #463

Open
BrentH-Alnico opened this issue Jan 16, 2025 · 6 comments
Open

Checkboxgroup issue when used with View Model #463

BrentH-Alnico opened this issue Jan 16, 2025 · 6 comments

Comments

@BrentH-Alnico
Copy link

Hi Boris,

I am converting plain objects/arrays project to use View Models.

When using plain objects/arrays I have no problems with checkboxgroup in this scenario.

When using View Models I am getting error: data.MayInviteOthers_list is not a function.

Here's a stripped down jsfiddle for testing.
https://jsfiddle.net/alnico/57Ldgs8e/

To test:

  1. On page load, no error.
  2. toggle radio to 'Normal', no error.
  3. toggle radio to 'Edit', error: not a function.
  4. Reload page, switch back and forth on tabs, no error interestingly... {{if...}} tag mounts/unmounts data...why no error here.
  5. If you use inline data-link="{checkboxgroup ~People.MayInviteOthers_list()}", no errors in any scenario.
{^{checkboxgroup MayInviteOthers_list() ".MayInviteOthers_list"}} 
   {^{for PeopleList() ~People=#data}} 
      {^{if ~root.IsEditing()}}

         {{!-- error --}}
         <label class="checkbox pb-2">
            <input class="MayInviteOthers_list" type="checkbox" value="{{:GUID()}}" /> 
            May Invite Others
         </label>

         {{!-- no error
            <label class="checkbox pb-2">
               <input type="checkbox" value="{{:GUID()}}" data-link="{checkboxgroup ~People.MayInviteOthers_list()}" /> 
               May Invite Others
            </label>
         --}}
         
      {{/if}} 
   {{/for}} 
{{/checkboxgroup}}
@BorisMoore
Copy link
Owner

Thanks Brent, for reporting this issue, and the other related ones. I hope to investigate further, though it might take a little whiile...

@BorisMoore
Copy link
Owner

Hi Brent - here is a candidate fix for issues 463 464 465 and 466.
Can you test it in your environment?

jsviews16 Candidate A.js.txt

You should no longer get the "data.MayInviteOthers_list is not a function" error

@BrentH-Alnico
Copy link
Author

BrentH-Alnico commented Jan 28, 2025

This fix works.
It also fixes an issue where I resorted to using visible{...} a month ago, not really knowing if it was a real 'issue' or a context issue on my side.
Awesome, thanks!

@BrentH-Alnico
Copy link
Author

Hi Boris,

Although candidate v16 fixed the issue reported above, I have another checkboxgroup that worked once upon a time but no longer (was buried, so I didn't notice it).

Using v15, I get error data.propName is not a function.
Using candidate v16, I get error Cannot read properties of undefined (reading 'base')

Note: this issue seems different than the one reported above...
I have a control that conditionally displays a {{block}}, but it is when I click on the input...checkbox bound to checkboxgroup that I get the error Cannot read properties of undefined (reading 'base').

I did some snooping to see if candidate v16 had an update that may have broken something (also testing my hacking skills ;-)...
I couldn't find anything (not surprising to me because this is over my head ;-), but I used Claude to assist and tried the following block of code...To my surprise it worked!
However, I do not know if this is an appropriate fix.

New code

function getDerivedMethod(baseMethod, method) {
   return function () {
      var ret,
         tag = this,
         prevBase = (tag && tag.base) || null;

      if (tag) {
         tag.base = baseMethod; // Within method call, calling this.base will call the base method
         ret = method.apply(tag, arguments); // Call the method
         tag.base = prevBase; // Replace this.base to be the base method of the previous call
      } else {
         // Fallback if tag is undefined - call method directly
         ret = method.apply(this, arguments);
      }
      return ret;
   };
}

Old code

function getDerivedMethod(baseMethod, method) {
   return function () {
      var ret,
         tag = this,
         prevBase = tag.base;

      tag.base = baseMethod; // Within method call, calling this.base will call the base method
      ret = method.apply(tag, arguments); // Call the method
      tag.base = prevBase; // Replace this.base to be the base method of the previous call, for chained calls
      return ret;
   };
}

If you need to see my code I can get it to you...

Thanks,
Brent

@BorisMoore
Copy link
Owner

BorisMoore commented Feb 1, 2025

Thanks Brent.
Any chance of a small repro, to show the context in which this error is coming up? Yes - maybe a small piece of your code. ;-)

@BrentH-Alnico
Copy link
Author

Hi Boris,

I sent you test file testCanidate16A_forBoris.html...sorry, no small file.

HTML line in question: 669 dateTime_voteOfficial

Using Candidate v16A

  1. Click checkbox Finalize Event.
  2. Click checkbox 4 PM...TypeError: Cannot read properties of undefined (reading 'base')

  1. If checkbox Finalize Event is initially checked, line: 2073 StopVoting: 1
  2. Click checkbox 4 PM...works as expected (This scenario also works with v15)

Using v15

  1. Click checkbox Finalize Event...TypeError: data.makeVotesOffical is not a function

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