Comments (9)
Thanks, glad to hear they are working for you! I didn't know 2.2.0 was out so I will definitely get on updating my code. It might take me a few days to complete as I will need to update my application to using 2.2.0 first because it serves as a good testing ground for the modals. If you don't mind waiting I will get an update out asap otherwise I will also gladly accept a pull request :)
Thanks
from bootstrap-modal.
No hurry, I just patched your code locally.
By the way, the reason why you want focus called before shown is because it allows you to override the focus behavior. I have a 'ModalHelper' class that by default automatically selects the first form element as the focus when the shown event is called. If no form element is in there, it will also try to look for class="focus". Pretty much every form 'editor' on my site is done in a modal now so this makes it really easy to work with things.
from bootstrap-modal.
Ah, makes sense. Your ModalHelper class sounds interesting, do you have any code I could take a look at by chance? I also incorporate similar, but manual behaviour in my application so I'd be curious to see how you've done it.
Thanks
from bootstrap-modal.
This is the class. Apologies if you dislike CoffeeScript, but I'm a huge fan. ;-) https://gist.github.com/3983303
It is kind of specific to my application as it references a few helper classes that I've got and the way that I deal with the logic in the modals, but it should give you a general idea for how it works. The idea is that I can apply different decorators (features) depending on what the functionality of the modal is. For example, some modals need to remain open after clicking a button (to show an error) while others need to automatically close no matter what.
The modal features enable public methods and under the covers apply all sorts of crazy callbacks. I suspect I'll rewrite this whole class someday to be a lot cleaner, but the first pass enabled me to at least get the logic all into a single location / api.
If you go to the homepage of my site, click on the little icon in the bottom left corner of the map. This is the code which handles that modal.
define (require) ->
util = require('app/util/common')
forms = require('app/util/forms')
ModalHelper = require('app/ModalHelper')
HasFields = require('app/HasFields')
FieldLocator = require('app/locator').FieldLocator
return class PickLocationModal extends HasFields
constructor: (@top) ->
super()
@modal = $('#pickLocationModal')
fields = ['#location']
@addFields(fields, @modal)
@locator = new FieldLocator
element: @d.location
placeChanged: => @helper.validateSimple()
@helper = new ModalHelper(@, @modal, ['oneSubmitButton', 'simpleSubmitButton'])
@helper.validate = (dirty, event, data, formData) =>
hasLoc = @locator.hasLoc()
forms.controlError(@d.location, => hasLoc)
dirty && hasLoc
@helper.submit = (top, formData) =>
@d.location.val(null)
@modal.modal('hide')
geo = @locator.getLoc().geo
@top.map.panTo(new L.LatLng(geo.latitude, geo.longitude))
I also make heavy use of dirtyform to enable/disable the Save button in a modal. That is part of that validate function above.
It can be hard to read others code without full context. If you have any questions, feel free to ask. I'm happy to share.
from bootstrap-modal.
Very cool, site looks really well done as well. Thanks for sharing, I always enjoy seeing how other people have solved some of these common UI problems. I hope to get around to writing some of these types of helper classes for my application as well.
from bootstrap-modal.
Updated the files to reflect bootstraps 2.2 changes. I however had one problem with changing the order in which setFocus() is called. I was experiencing a weird problem where the 2nd time a modal is open, the background page would scroll all the way to to top. I could not figure out what was causing this so I instead just check for e.isDefaultPrevented()
and do not focus if true.
Hope that is an adequate solution but let me know if you have any issues with that.
Thanks
from bootstrap-modal.
Hmm... I think what you missed is around this line:
You need to add .focus() in there so it looks like this:
transition ?
modal.$element.one($.support.transition.end, function () { modal.$element.focus().triggerHandler('shown') }) :
modal.$element.focus().triggerHandler('shown');
and I just commented out the handler for shown.modalmanager...
/*
modal.$element.on('shown.modalmanager', function(e){
that.setFocus();
})
*/
from bootstrap-modal.
Yep that was it. I was setting focus before the transition had finished which caused the weird behaviour I was seeing.
Thanks
from bootstrap-modal.
Thanks, it is working great now.
from bootstrap-modal.
Related Issues (20)
- is there any compatibility issues with select2.js? HOT 1
- Construct ajax query (ie. ajax Contact form)
- can i use this without bootstrap HOT 1
- angular 1.2.* ng-include used inside ui-bootstrap - modal opening page scrolls to top
- Show Modal Without overlay.
- Modal opens with a delay compared to standard BS3 modal
- Use modal with form validation
- body class="modal-open" style="padding-right: 15px" HOT 1
- Modal don't scroll when closing top modal
- The bootstrap dependency is different between github repo and bower repo.
- make collapsable?
- event.relatedTarget()
- How to relocate modal inside into a div
- Publish as NPM package
- Incompatible with Boostrap 4? HOT 4
- when using this with bootbox.js ,the bootbox dialog style was confused HOT 9
- Stackable: Close modal when clicked outside
- Will you upgrade to Bootstrap 4? HOT 1
- event listener for complete loading
- Replaced # with javascript:; in this statement and it worked.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bootstrap-modal.