Code Monkey home page Code Monkey logo

jquery-bindings's Introduction

example

jquery-bindings

Simple two-way data binding using proxies and requestIdleCallback (661 Bytes gzipped)

Table of Contents

Table of Contents
  • Install
  • Install
  • Usage
  • API
  • Contribute
  • License
  • About

    Inspired by a pen, simple data bindings that rely on Proxies (ensure this is polyfilled for older browsers) and requestIdleCallback (Shimmed if not available).

    Install

    <script src="https://cdn.rawgit.com/tiaanduplessis/jquery-bindings/master/jquery-bindings.min.js"></script>
    <!-- Or -->
    <script src="https://unpkg.com/jquery-bindings/jquery-bindings.min.js"></script>
    • Using package manager:
    $ npm install jquery-bindings
    # OR
    $ yarn add jquery-bindings

    Usage

    Create html with data-bind attributes:

    <p>
        <label>First Name:</label>
        <input type="text" data-bind="firstName" />
        <label>Last Name:<label/>
        <input type="text" data-bind="lastName" />
        <br> Age:
        <input type="number" data-bind="age">
    </p>

    create a initial object and initialize $.bindings

    var obj = {
      firstName: 'Tiaan',
      lastName: 'du Plessis'
    }
    
    var bindings = $.bindings(obj)
    
    // bindings variable can be updated directly and trigger DOM updates
    // DOM updates will trigger updates in the bindings variable 
    
    bindings.firstName = 'Dupie'
    
    // New properties can be added as long as the associated data-bind attribute exists
    bindings.age = 24

    See the example for more information.

    API

    $.bindings(object, options)

    object

    • Plain JS object

    options

    attribute
    • Name of attribute to bind. defaults to data-bind

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.

    jquery-bindings's People

    Contributors

    greenkeeper[bot] avatar halil07 avatar renovate-bot avatar tiaanduplessis avatar

    Stargazers

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

    Watchers

     avatar  avatar  avatar

    jquery-bindings's Issues

    Data Binding Not Working with Dynamic Elements

    Hello,
    Thank you so much for this great library. I came across an issue in data binding while working with dynamic elements (created by ajax). Data Binding has no effect on dynamically created elements, however its working fine with normal elements.
    Please check this issue, when you'll have some time.
    Thanks a lot!

    Delay when write on any text field

    I have experimenting a delay when write in an input with a binding. If I write very mainly in chrome browser the delayed binded values overwrite the text that I am writing in the field removing some characters.

    Bind not working

    I have exactly the same example HTML but the binding are not working.

    Then I have in my HTML:

     <div class="form-group">
         <label for="name">Nombre:</label>
        <input type="text" class="form-control" name="name" id="name" data-bind="name" required>
     </div>
    <span data-bind="name"></span>
    

    At the end of the HTML I have referenced:

    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js" integrity="sha256-+BEKmIvQ6IsL8sHcvidtDrNOdZO3C9LtFPtF2H0dOHI=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js" integrity="sha256-yUWanhHkxj+3ow0qZE6AtzP8lZkwLvPagULL6PnZMz0=" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/jquery-bindings/jquery-bindings.min.js"></script>
    

    this Is my initialization inside fo document.ready:

    let obj = {
       name: '',
       email: '',
       phone: '',
       address: '',
       instructions: '',
       billing: '',
       fileGroupList: []
     }
    
     let dataToSend = $.bindings(obj)
    

    But finally not working but no errors on console.

    fast typing skips some letters

    i noticed that typing fast in a text box sometimes skips some letters

    setup:
    tiaanduplessis-jquery-bindings-v1.0.1-0-gcbce956
    jquery 3.3.1
    semantic ui 2.2.6

    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.