Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:25:29+00:00 2026-06-13T06:25:29+00:00

As I dig deeper into the concepts of knockout.js, I’m having difficulties to understand

  • 0

As I dig deeper into the concepts of knockout.js, I’m having difficulties to understand why I can’t tell a ko.observable how to parse/write its value like so:

   dateValue = ko.observable({
        read: function (dateString) {
            /*convert a date string to an object here for internal storage*/
            return Globalize.parseDate(dateString, 'd');
        },
        write: function (dateObj) {
             /*format a date object for output*/
            return Globalize.formatDate(dateObj, 'd');
        }
    })

I’m aware that ko.computed’s exist for this purpose, but they still require me to keep a “shadow” observable where the result of read() needs to be written to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:25:31+00:00Added an answer on June 13, 2026 at 6:25 am

    Write an extender to add a formatted computed observable so you may read or write formatted values while still giving you access to the “raw” unformatted value.

    ko.extenders['date'] = function (target, format) {
        var formatted = ko.computed({
            'read': function () {
                return Globalize.parseDate(target(), format);
            },
            'write': function (date) {
                target(Globalize.format(date, format));
            }
        });
        target.formatted = formatted;
        return target;
    };
    
    dateValue = ko.observable('10/19/2012').extend({ 'date': 'd' });
    
    // e.g.,
    dateValue();           // 10/19/2012
    dateValue.formatted(); // Fri Oct 19 2012 00:00:00 GMT-0700 (Pacific Daylight Time)
    
    dateValue.formatted(new Date(2012, 9, 31));
    
    dateValue();           // 10/31/2012
    dateValue.formatted(); // Wed Oct 31 2012 00:00:00 GMT-0700 (Pacific Daylight Time)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes one needs to dig into someone else's code, understand it and maybe refactor/fix
I am having a specific leak that I can't seem to dig to the
I'm trying to dig a little deeper into clojure and functional programming. At some
Which class or delegate should I sub-class to dig deeper into the call-stack of
This may be the wrong approach, but as I dig deeper into developing my
Before I dig deeper into the rabbit hole... a quick question... is it possible?
I want to dig deeper into Django's internals and the official online documentation only
I'm beginning to dig a little deeper into JavaScript development and would like to
I'm trying to dig a bit deeper into parallelziation of R routines. What are
When building advanced JS-interfaces and games I've found that I have to dig deeper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.