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 7733005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:52:29+00:00 2026-06-01T06:52:29+00:00

I have a edit in place section to which I want to add a

  • 0

I have a edit in place section to which I want to add a confirmation of changes before the knockoutjs model is updated.

Here’s the jsFiddle example of what I have now.
Here’s what I would like it to do.

  1. User clicks on editable section
  2. textbox appears with save/cancel buttons next to it.
  3. if user makes a change and clicks save, view model is updated
  4. if user makes a change, but decides to keep the original content, they click cancel, view model remains unchanged, texbox is hidden, and editable element remains unchanged.

The behavior of the cancel click is what I’m not sure how to implement. Can anyone suggest how this could be done?

  • 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-01T06:52:30+00:00Added an answer on June 1, 2026 at 6:52 am

    I prefer to use custom binding handler for this.
    Example http://jsfiddle.net/7v6Dx/10/

    Html

    <div>
        <span class="editField">
            <span data-bind="text: Address1">Click here to edit</span>
            <input type="text" data-bind="clickEditor: Address1">
        </span>
    </div>​
    

    JavaScript

    ko.bindingHandlers.clickEditor = {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel) {        
            var $element = $(element).hide();
            var $text = $element.prev();
            var $buttons = $("<span class='editConfirm'> \
                        <button class='saveEdit' type='button'>Save</button> \
                        <button class='cancelEdit' type='button'>Cancel</button> \
                    </span>").hide().insertAfter($element);
            var $editElements = $buttons.add($element);
    
            ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
                $buttons.remove();
            });
    
            var _toggle = function(edit) {
                $text[edit? 'hide' : 'show']();
                $editElements[edit? 'show' : 'hide']();
            }
    
            $text.click(function(e) {
                _toggle(true);
            });
    
            $editElements.find('.saveEdit').click(function() {
                _toggle(false);
                valueAccessor()($element.val());
            });
    
            $editElements.find('.cancelEdit').click(function() {
                _toggle(false);
                $(element).val(ko.utils.unwrapObservable(valueAccessor()));
             });
        }
        , update: function (element, valueAccessor) {
            $(element).val(ko.utils.unwrapObservable(valueAccessor()));
        }
    };
    
    $(document).ready(function() {
        var helpText = "Click here to edit";
    
        function appViewModel() {
            this.Address1 = ko.observable(helpText);
        }
        ko.applyBindings(appViewModel());
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perl one-liner in a Makefile to edit files in place: perl
I won't want to have edit any working sets. I just want a way
I have an edit text which functions as a search box in my application.
I have 3 (Edit) mutually exclusive IEnumerables that I want to iterate over. I
I have a page where i'm using edit-in-place... now, after the update it's showing
near the end of <head> section (but not immediately before </head> ) I have:
I have two Edit Fields Username and Password and everytime i revert back to
I have 2 edit texts. I will type a message in one of the
I have an edit form, where the values are populated from the database. I
I have a edit View - Product/Edit/1 1 being the Id of the Product.How

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.