Giter Site home page Giter Site logo

knockout-freedom's People

Contributors

mbest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

knockout-freedom's Issues

knockout computed read and write

Hi, I have a computed function with read and write.
now when I write to the computed function I wanted to apply some validation logic in the write part. if the validation fails, I don,t want it to be written to the computed function. also I don't want the subscription to happen which is already configured to the computed function.

please advice.

AMD compatible?

Several of your other plugins are AMD-compatible; plans to add that to this one?

mandatory textbox and just tabbing out should show the required error message.

Hi,
1st requirement - I have designed a form which has two text input control. where both are mandatory. now when the user just tabs out without entering and the text box looses focus the error message should be displayed. I am using knockout-validation with custom rules written.

2nd requirement - on click of the submit button, for all the text input if the rule fails it should show error message.

currently I am using hasfocus with few rules written to it. it works, but in chrome/safari and firefox 22 it takes 2 tabs to come out of the text input.

please advice.

why not use a computed as the wrapped value?

ko.bindingValueWrap currently wraps the binding value using a psuedo-observable function. It may seem like ko.computed would do the job just as well. That is actually true (mostly). The problem with using ko.computed here is that it needs to be disposed when the element is removed, but there's currently no way to get the element in ko.bindingValueWrap. This would change If/when knockout/knockout#474 is included in Knockout.

ko.bindingValueWrap using ko.computed and element:

ko.bindingValueWrap = function(element, valueAccessor, valueWriter) {
    var valueFunction = ko.computed({
        read: function() {
            return ko.utils.unwrapObservable(valueAccessor());
        },
        write: function(valueToWrite) {
            var value = valueAccessor();
            if (ko.isObservable(value)) {
                value(valueToWrite);
            } else if (valueWriter) {
                valueWriter(valueToWrite);
            }
        },
        disposeWhenNodeIsRemoved: element
    });
    ...
    return valueFunction;
};

Here's a version that could work right now, but doesn't dispose the computed until it's updated:

ko.bindingValueWrap = function(valueAccessor, valueWriter) {
    var valueFunction = ko.computed({
        read: function() {
            return ko.utils.unwrapObservable(valueAccessor());
        },
        write: function(valueToWrite) {
            var value = valueAccessor();
            if (ko.isObservable(value)) {
                value(valueToWrite);
            } else if (valueWriter) {
                valueWriter(valueToWrite);
            }
        },
        disposeWhen: function() {
            return !valueFunction.getSubscriptionsCount();
        }
    });
    ...
    return valueFunction;
};

mandatory textbox and just tabbing out should show the required error message.

Hi,
1st requirement - I have designed a form which has two text input control. where both are mandatory. now when the user just tabs out and the text box looses focus the error message should be displayed. I am using knockout-validation with custom rules written.

2nd requirement - on click of the submit button, for all the text input if the rule fails it should show error message.

currently I am using hasfocus with few rules written to it. it works, but in chrome/safari and firefox 22 it takes 2 tabs to come out of the text input.

please advice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.