Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Caleb Kniffen
@ckniffen
?
Kent C. Dodds
@kentcdodds
no, it's a little more complex
wish I had time to explain, but we're going to demo in a second and I have a bug or two to squash
Caleb Kniffen
@ckniffen
Thats fine
Kent C. Dodds
@kentcdodds
I think that's my next egghead.io lesson
Caleb Kniffen
@ckniffen
:)
Kent C. Dodds
@kentcdodds
because it's pretty complex, way powerful, very confusing
Benjamin Cabanes
@bcabanes
Hi guys, i have to do an "emptyIfEmpty" validation and i really don't know how to do it. Do you have implemented one?
Kent C. Dodds
@kentcdodds
I'm not sure what "emptyIfEmpty" means...
Benjamin Cabanes
@bcabanes
By emptyIfEmpty i mean:
i have two fields, if the first has a value, and the second hasn't, then the two must be empty
it's like dependent fields that have to be all filled, or all empty.
I don't really sure it is possible with formly, but i ask anyway
Kent C. Dodds
@kentcdodds
It's totally possible (and easy) with formly
I just don't have time to give you an example right now
Benjamin Cabanes
@bcabanes
okay, so this is a good news, an example would be super great! when you'll have time.
Kent C. Dodds
@kentcdodds
I recommend checking out the validation lesson at http://learn.angular-formly.com
Benjamin Cabanes
@bcabanes
yep i already tried that but i mess up with catching another value from the model but i will continue to try.
Ben Orozco
@benoror
you could write a failing jsbin example
Benjamin Cabanes
@bcabanes
i'll do that
Benjamin Cabanes
@bcabanes
Just make a jsbin http://jsbin.com/huhewo/4/ of the empty if empty failing
Ben Orozco
@benoror
@bcabanes the answer is in the validation example: http://angular-formly.com/#/example/other/toggle-required
by using expressionProperties to set required bound to each other, here's your jsbin fixed: http://output.jsbin.com/qodele/1/
Benjamin Cabanes
@bcabanes
@benoror I think this will do the trick, thank you!
Ben Orozco
@benoror
:+1:
Ken
@thekennysong
I am trying to use hideExpression and || . however hideExpression: 'model.primary_packaging !== "tray" || model.primary_packaging !== "shelf_carton"' doesn't work. I am sure it is small but idk how to fix it
Caleb Kniffen
@ckniffen
@thekennysong does it work without the OR?
Ken
@thekennysong
@ckniffen no i couldn't get it. I know it is a small little thing, but i tried a bunch of different combinations, no luck though
Caleb Kniffen
@ckniffen
where are you putting the hideExpression in the defintion? It needs to be at the top level (same level as key). That is a common mistake.
Ken
@thekennysong
                        key: 'quantity',
                        type: 'input',
                        templateOptions: {
                            label: 'Quantity',
                            type: 'text'
                        },
                        hideExpression: 'model.primary_packaging !== "tray"'
                    }
it works with 1
Kent C. Dodds
@kentcdodds
Make sure that the logic is doing what you think it's doing.
'model.primary_packaging !== "tray" || model.primary_packaging !== "shelf_carton"' means that the field will hide if the primary_packaging is not equal to tray or shelf_carton
If that's what you're trying to do, then could you make an example: http://new-example.angular-formly.com
Kent C. Dodds
@kentcdodds
@/all I will only accept a PR for this one if you haven't ever contributed to open source before :-) https://github.com/formly-js/angular-formly/issues/343#issuecomment-111495740
I'm willing to hold your hand through it.
Caleb Kniffen
@ckniffen
Nice
Kent C. Dodds
@kentcdodds
Though, I'll probably only wait a few days, because I'd like to get this feature in :-)
matthew harwood
@matthewharwood
@kentcdodds hey man have you tried to run any unit tests with angular 2?
Kent C. Dodds
@kentcdodds
nope, not yet @matthewharwood
matthew harwood
@matthewharwood
Dang thanks :)
Kent C. Dodds
@kentcdodds
I would recommend you ask the people in the https://gitter.im/angular/angular room
Kent C. Dodds
@kentcdodds
Hey, if anyone has some time, I'm trying out some features of codecov.io. If someone could write a test for formly-focus and submit a PR that'd be great. I want to see the codecov status / comment features on the PR. Or if you don't want to setup a whole new test file, you could create a test for formlyConfig.extras.disableNgModelAttrsManipulator in formlyNgModelAttrsManipulator. Anyway, I'd really appreciate it!
Abdullah Mohammed
@abodacs
@benoror great work @panax i have a question how do you store form configuration at backend ?
Ben Orozco
@benoror
Hi @abodacs sorry for the delay, I will pm you
Or we can chat in panaxit/panaxit channel
websta
@websta
Hi All! I'm using formly to display data retrieved via $http from Java backend containing an unix timestamp (milliseconds). I wrote a method, which translated the timestamp with moment.js into a JS Date object, added an additional field (for display purposes) on the object and provided it to formly. On submit, another method updates the unix timestamp from the formly input and transmittes the data back to the backend. But the backend does not accept an additional field. So, I tried to implement this kind of translations with formly-fieldconfig-controller and templateOptions.onBlur. The controller triggers on load and updates the model value perfectly, but the onBlur event has only access to field and scope without the model. So submitting the formly input only contains the JS Date Object. Could you give me any suggestions please?
```
'templateOptions': {
'onBlur': function(field, $scope) {
var newValue = (function dateConversion(oldValue) { return parseInt(moment(oldValue).format('x'), 10); })($scope.value);
// Change in model
$scope.value = newValue;
$scope.formControl.$modelValue = newValue;
}
},
controller: function ($scope) { // code from formly gitter chat
var newValue = (function dateConversion(oldValue) {
return moment(oldValue).toDate();
})($scope.model[$scope.options.key]);
// Change in model
$scope.model[$scope.options.key] = newValue;
// Change original value as well (keep in $pristine)
$scope.options.value = newValue;
}
ยดยดยด
Kent C. Dodds
@kentcdodds
If you want to have a field for view purposes only, set it's model to formControl
so: model: 'formControl'
Caleb Kniffen
@ckniffen
@websta The way I got around a similar situation was to create a new field type that did that instead of externally updating it
Kent C. Dodds
@kentcdodds
another thing you may consider is using parsers and formatters...
Thinking about implementing an api for those in formly... Report an issue if you're interested :-)