These are chat archives for canjs/canjs

26th
May 2016
Mason Shin
@minsooshin
May 26 2016 00:36 UTC
sorry, I was on urgent stuff..
for can-validate, I need to define the observe like this
const foo = can.Map.extend({
  define: {
    email: {
      value: ‘’,
      validate: {
        email: true
      }
    }
  }
});
But I would like to add that rule data driven.
If I add more with .attr, it doesn’t update with define
So, I generate an object by data, and set the define value with it.
FormRule = Map.extend({
  define: rule
});
Mason Shin
@minsooshin
May 26 2016 00:42 UTC
So, I solved that problem, but I met another problem with can-validate
after I installed can-validate module, I got this failure message on test
undefined is not a constructor (evaluating 'Array.from(fragment.childNodes)')
but it only happens on phantom :(
browser testing works fine
Mason Shin
@minsooshin
May 26 2016 01:26 UTC
okay
fixed it. :)
Mason Shin
@minsooshin
May 26 2016 01:32 UTC
I have used conversion for nodelist to array with Array.from
but I need to use Array.prototype.slice for phantom after installing can-validate
Anyways, it is still strange, why can-validate affects on it...
Michael Price
@web-mech
May 26 2016 16:02 UTC
is there a way to stop the can-validate map plugin from validating maps on every change? I have a few computed validation rules and it seems they are aggressively validated on every update
6: {
    Type: can.Map.extend({
      define: {
        'selection': {
          type: 'number',
          value: -1,
          validate: {
            numericality: function() {
              return {
                greaterThan: user.attr('5.selection') === 1 ? -1 : -2
              };
            }
          }
        }
      }
    }),
    value: {}
  }
As soon as attribute 5.selection is 1, 6.selection is validated immediately without calling validate on the map
Michael Price
@web-mech
May 26 2016 16:10 UTC
doing this post validate makes sense, but immediate validation on this is problematic as its validating before the user even has a chance to fill out the form
i’ve also tried things like setting validateOnInit to false
Dovid Bleier
@dbleier
May 26 2016 16:28 UTC
what is the latest version of can-connect?
latest published version at least
Dovid Bleier
@dbleier
May 26 2016 16:31 UTC
whoa! I'm still on v0.3.6, guess I need to upgrade. Thanks @web-mech
Michael Price
@web-mech
May 26 2016 16:31 UTC
np
Michael Price
@web-mech
May 26 2016 16:43 UTC
also, i’m finding that this https://github.com/ansman/validate.js/blob/master/validate.js#L250 causes problems where this in a validation compute is null
{
  validate: {
    required: function(value, map) {
      map // undefined
      this // is null
      return this.attr('foo') === true; //throws error
    }
  }
}
@justinbmeyer any recommendations?
Michael Price
@web-mech
May 26 2016 16:54 UTC
@Macrofig ?
Thomas Sieverding
@Bajix
May 26 2016 17:29 UTC
@web-mech boop
Michael Price
@web-mech
May 26 2016 17:29 UTC
@Bajix beep?
Thomas Sieverding
@Bajix
May 26 2016 17:30 UTC
The easiest way I’ve found to do validation is to combine server side + client side validation
And then make the client side validation skip on default values
That’s my attempt at normalizing error objects for validation
Essentially converts expess-validator errors that are in array syntax mode, as well as MongoDB errors, and standardizes on node-restify-errors
Chris
@chrischrischris
May 26 2016 17:37 UTC
is there an equivalent component event to the ($enter) view binding? E.g: 'input enter' : function ...
Michael Price
@web-mech
May 26 2016 17:57 UTC
@chrischrischris if not using can v3.x you can use the deprecated syntax although probably not reccomended https://canjs.com/docs/can.view.bindings.can-EVENT.html#section_SpecialEventTypes
can-enter='{save}’
Chris
@chrischrischris
May 26 2016 17:59 UTC
Ok thanks for the link - we're on 2.3. I'll just use the view bindings
Michael Price
@web-mech
May 26 2016 17:59 UTC
actually looks like ($enter) is supported https://canjs.com/docs/can.view.bindings.event.html
Chris
@chrischrischris
May 26 2016 17:59 UTC
yeah - what I wanted was to have it in the components events object
Michael Price
@web-mech
May 26 2016 17:59 UTC
ah
Chris
@chrischrischris
May 26 2016 18:00 UTC
I can use keypress and check for 13, but enter seemed more elegant and performant
Dovid Bleier
@dbleier
May 26 2016 19:40 UTC
I have following viewModel for a component
export const ViewModel = Map.extend({
  define: {
    props: {
      type: '*',
      value: {
          isActive: true,
          schedulingOn: false,
          externalOn: false,
          streamingOn: false
      }
    }
  },
});
which has boolean values
but when I view in devTools they are strings
$('advanced-tab').viewModel().attr('props')
Map {_data: Object, _cid: ".map1141", _computedAttrs: Object, isActive: "true", schedulingOn: "false"…}
__bindEvents: Object_bindings: 11
_bubbleBindings: Object
_cid: ".map1141"
_computedAttrs: Object
_data: Object
externalOn: "false"
isActive: "true"
schedulingOn: "false"
streamingOn: "false"
__proto__: can.Construct
so when I have in stache
<div class="checkbox">
  <label><input type="checkbox" id="schedulingOn" 
              {($checked)}="props.schedulingOn">Scheduling On</label>
</div>
{{#if props.schedulingOn}}
    <can-import from="cms/tabs/advanced-tab/presentation-scheduler/" />
    <presentation-scheduler {schedule}="props.schedule"></presentation-scheduler>
{{/if}}
it's always true
anyone know why it's converting the booleans to strings?
Michael Price
@web-mech
May 26 2016 19:45 UTC
try refactoring your view model to look like this
export const ViewModel = Map.extend({
  define: {
    props: {
      Type: Map.extend({
        define: {
          isActive: {
            type: 'boolean',
            value: true
          },
          schedulingOn: {
            type: 'boolean',
            value: false
          },
          externalOn: {
            type: 'boolean',
            value: false
          },
          streamingOn: {
            type: 'boolean',
            value: false
          } 
        }
      }),
      value: Object
    }
  }
});
@dbleier
Dovid Bleier
@dbleier
May 26 2016 19:47 UTC
ok, I wanted to have them all grouped under a props property, but I guess I can do it this way. thanks again @web-mech
Michael Price
@web-mech
May 26 2016 19:47 UTC
well, this essentially turns props into a can map, which has defined types. So your boolean flags will be coerced into booleans instead of strings
Dovid Bleier
@dbleier
May 26 2016 19:48 UTC
I understand
Michael Price
@web-mech
May 26 2016 19:48 UTC
so your viewmodel still has a props property, its just well defined now with types
Dovid Bleier
@dbleier
May 26 2016 19:49 UTC
oh, didn't see you kept that at the top, aha!
it worked!! thanks again!
Michael Price
@web-mech
May 26 2016 19:50 UTC
nice!
np
Dovid Bleier
@dbleier
May 26 2016 19:51 UTC
I'll post this to forum in case someone else ever has the same issue
Michael Price
@web-mech
May 26 2016 20:39 UTC
:+1: