Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Check boxes in ibook author?

Can you insert a check box in the ibook pages? I am trying to set up a template.

iBook, Mac OS X (10.7.3)

Posted on Mar 10, 2012 11:49 PM

Reply
28 replies

Mar 11, 2012 8:56 PM in response to Fabe

Within a table I am trying to create a list where others using this template could check the components they are using. I tried to incorporate the Review Widget, which is awesome for teachers, but it will not incorporate in my table. They are familiar with this template outside or ibook so I want to make sure it looks as similar as possible. Is there anyway that the widget can be incorporated. A box image won't work because it has too be check-able. I usually use the Developer feature in Word. Any help is greatly appreciated.!!!

Mar 12, 2012 4:22 PM in response to IvettefromCa

I'm working on this myself. Widgets will work - you can simply design a page with HTML checkboxes and copy/paste the code into the something like Hype or Edge, then export as a widget. The problem is a limitation in the way widgets work. When you click on a widget, it takes over the screen. But when you close the widget, it returns to it's default, original state. So if you create a checkbox widget, that means all your checkmarks will be reset when you exit the widget or turn the page. It's a kludge. I'm sure Apple will have to work on this for the next version. But four now, it's frustrating.

Mar 12, 2012 6:11 PM in response to Captain Digital

The problem is that widget.setPreferenceForKey() and widget.preferenceForKey() don't work when you run the widget inside iBooks, so you can't persist the state of the widget with these.


In addition, the following code does nothing in iBooks:


if (window.widget) {

widget.onremove = remove;

widget.onhide = hide;

widget.onshow = show;

widget.onsync = sync;

}


It looks like these events are never sent when a widget runs in iBooks.


I tried registering a handler for onremove, but it appears that this event is also not delivered when running in iBooks.


(There are many more problems such as this. For example, none of the classes provided by Apple with Dashcode work in iBooks. Things like sliders, the info button, the front-back transition for widgets--none of these work in iBooks.)


The only way I've found to persist widget state is to use localStorage for the persistent state, and to schedule saving persistent state with a timer. Basically, every time there is a state change in the widget, I call a scheduleSavePrefs() function:


function scheduleSavePrefs()

{

if (scheduleSavePrefs.timer)

{

clearTimeout(scheduleSavePrefs.timer);

}

scheduleSavePrefs.timer = setTimeout("savePrefs()", 3000);

}


This clears any previous timer and then sets a timer 3 seconds in the future. The idea is that, if the user doesn't make a state change for 3 seconds, the current settings are saved automatically. The 3-second delay makes sure that I don't hammer local storage for rapidly changing state, such as when moving a slider.


I call scheduleSavePrefs() from all event handlers that change the state of the widget.


The savePrefs() function stashes the values I care about away in local storage. Something like:


var myCounter = 99;


function savePrefs()

{

localStorage.myCounter = myCounter.toString();

// ...

}


On load, I call a loadPrefs() function that initializes the widget from local storage.


function loadPrefs()

{

var c = localStorage.myCounter;

if (c)

{

myCounter = parseInt(c);

// ...

}

}


I know, this is a lot of hoops to jump through just to get things to work in iBooks, but it's the best I've been able to come up with. If anyone has suggestions for improvement, I'd love to hear them!


Cheers,


Michi.

Mar 24, 2012 7:42 AM in response to MichiHenning

"Things like sliders, the info button, the front-back transition for widgets--none of these work in iBooks."


I've got sliders to work but not very well. Takes a double tap or two. Same with buttons.


Interesting code for local storage. I should give it a try. I have a state or two that would be nice to preserve for the individual reader between widgets.

Mar 24, 2012 4:22 PM in response to David Bourne

David Bourne wrote:


I've got sliders to work but not very well. Takes a double tap or two. Same with buttons.

The Apple slider doesn't work, at least not as intended. You cannot drag the thumb of the slider as you can when you run the same widget in Dashboard. Instead, you can change the slider position only by tapping. That's not how a slider is meant to work. (The problem is caused by the absence of mousemove events in iBooks, which the AppleSlider implementation relies on.)


Note that, if you use a plain HTML 5 range input element instead of the AppleSlider class, the slider works correctly. However, in this case, you are limited to horizontal sliders because Safari is not standard compliant and, as a result, cannot render a vertical slider. (You could create your own vertical slider with JavaScript, but doing that is fair amount of work.)


The double tap problem is caused by the presence of the info button in a widget. The info button doesn't work in iBooks because there is no mouseover event. If you merely have an infobutton element in your widget, it causes all other interactive elements, such as buttons, sliders, radio buttons, and so on, to not react to the first tap and receive an event only on the second tap. This happens even if you disconnect the infobutton from its event handler.


To fix the problem, delete the infobutton from the widget. Once you do that, events are posted to the other objects in the widget normally. (While you are at it, to save space, you might as well delete all elements on the back part of the widget because the front-back animation doesn't work in iBooks either, so you can't show the back of a widget in iBooks.)


Michi.

Mar 24, 2012 5:57 PM in response to MichiHenning

MichiHenning wrote:


a) The Apple slider doesn't work, at least not as intended. You cannot drag the thumb of the slider as you can when you run the same widget in Dashboard. Instead, you can change the slider position only by tapping. That's not how a slider is meant to work. (The problem is caused by the absence of mousemove events in iBooks, which the AppleSlider implementation relies on.)


b) Note that, if you use a plain HTML 5 range input element instead of the AppleSlider class, the slider works correctly. However, in this case, you are limited to horizontal sliders because Safari is not standard compliant and, as a result, cannot render a vertical slider. (You could create your own vertical slider with JavaScript, but doing that is fair amount of work.)


c) The double tap problem is caused by the presence of the info button in a widget. The info button doesn't work in iBooks because there is no mouseover event. If you merely have an infobutton element in your widget, it causes all other interactive elements, such as buttons, sliders, radio buttons, and so on, to not react to the first tap and receive an event only on the second tap. This happens even if you disconnect the infobutton from its event handler.


d) To fix the problem, delete the infobutton from the widget. Once you do that, events are posted to the other objects in the widget normally. (While you are at it, to save space, you might as well delete all elements on the back part of the widget because the front-back animation doesn't work in iBooks either, so you can't show the back of a widget in iBooks.)


Thank you for this info. Very useful. You are right about the sliders.


a) Agreed the sliders are rather bad. I went so far as to prgrammatically link them to an input field where you could enter the actual value... clumsy but it worked. I guess I'm hoping Apple will fix it some time (soon ;-) I'm encouraged by the Dashcode updates.


b) Horizontal sliders would be fine but how would I add them to a 'canvas'. I found using them in a <form> as an input http://www.w3schools.com/html5/html5_form_input_types.asp but how do I 'draw' that element to a canvas?


c) and d) Great news, sort of. I was all set to resubmit my book on Monday... maybe it will be Tuesday now :-) Looks like I'll have to 'recompile' (repackage) my widgets again. As simple as removing the info button. Great.


I've found a few differences between 'standard' JavaScript and the code snippets provided by Apple. Again, I was hoping Apple will fix them in time. Check boxes are one element I've had to work around using

"checkboxValue.firstElementChild.checked" to get the checked status.


Michi, many thanks for your help.


David


Update: Removing the info button helps a lot. The sliders work better too. They still don't slide but a single tap usually get the job done. Thank you. db

Mar 24, 2012 6:23 PM in response to David Bourne

David Bourne wrote:


b) Horizontal sliders would be fine but how would I add them to a 'canvas'. I found using them in a <form> as an input http://www.w3schools.com/html5/html5_form_input_types.asp but how do I 'draw' that element to a canvas?

You don't need a form to use a slider. You can put a slider anywhere in your HTML. Something like this will work fine:


<inputid="MySlider"type="range" min="0"value="140" max="513"onchange="mySliderChanged(event)">


I would strongly recommend to use something other than Dashcode to create your widgets. Dashcode is a very unreliable program. It frequently hangs or crashes. In addition, it has a habit of corrupting its own project file during a save. This means that, after a save, when you close down and re-open Dashcode and try to open the project file, you get an error "The document "abc" could not be opened. The isn't in the correct format. The file might be corrupted, truncated, or in an unexpected format."


This has happened to me with different projects on numerous occasions, trashing many hours of work in some cases.


Michi.

Apr 2, 2012 7:56 AM in response to MichiHenning

Michi


Thanks again for the info button removal suggestion. My widgets are like new...


What are you using besides Dashcode? I have Hype and have used it for an animation but it seems more complex than Dashcode. I'm doing a number of simulations, parameters plus graph, type widgets (Basic Pharmacokinetics: Truncated) and Dashcode has been useful in setting up the 'canvas'. The latest version is a little more stable ;-) although localStorage doesn't seem to work well with the 'Run' command. It does on the iPad. Maybe because there isn't a 'local' place in Dashcode.


Thanks again. David

Apr 2, 2012 4:48 PM in response to MichiHenning

Dreamweaver...thanks. I developed a bit of a workflow with Dashcode ;-) I open a duplicate project and immediately try to save it. If the save works without requiring a new filename I'm able to proceed with developement. It has been useful.


I had finally worked out that Dashcode doesn't have localStorage. I was pleased to see it works with iBooks. Maybe I can use Dashboard as an intermediate testing tool.


Thanks, David

Apr 2, 2012 6:41 PM in response to David Bourne

Be careful with that approach. Dashcode has destroyed more than one project file for me, even though I saved the project successfully without error. Everything appears to be just fine. Then I close down Dashcode and try to open the project, and get an error message about a corrupted project file.


Also watch things if you open a project and the canvas for the widget appears, but some of the elements of the widget are missing. Don't try and fix things when this happens. This is a bug in Dashcode, and if you keep working with the project, you will almost certainly end up with a corrupted project file. Instead, close the project immediately and the re-open it (using File -> Open). On the second attempt, the project file usually loads normally.


I recommend to take frequent backups when using Dashcode. The danger of ending up with a corrupted project file is large and real. Save frequently and stash a copy of the saved file away somewhere else. That way, when Dashcode finally makes a mess of things, you won't lose too much work.


Also, as you discovered, be wary if, during a save, you get a message about the project file not being found and getting prompted to pick a different save location. If that happens, it's over: you can no longer save the project anywhere, by any means, and the only way to recover is to kill Dashcode and use a backup copy.


Michi.

Apr 2, 2012 8:00 PM in response to MichiHenning

MichiHenning wrote:


a) Be careful with that approach. Dashcode has destroyed more than one project file for me, even though I saved the project successfully without error. Everything appears to be just fine. Then I close down Dashcode and try to open the project, and get an error message about a corrupted project file.


b) Also watch things if you open a project and the canvas for the widget appears, but some of the elements of the widget are missing. Don't try and fix things when this happens. This is a bug in Dashcode, and if you keep working with the project, you will almost certainly end up with a corrupted project file. Instead, close the project immediately and the re-open it (using File -> Open). On the second attempt, the project file usually loads normally.


c) I recommend to take frequent backups when using Dashcode. The danger of ending up with a corrupted project file is large and real. Save frequently and stash a copy of the saved file away somewhere else. That way, when Dashcode finally makes a mess of things, you won't lose too much work.


d) Also, as you discovered, be wary if, during a save, you get a message about the project file not being found and getting prompted to pick a different save location. If that happens, it's over: you can no longer save the project anywhere, by any means, and the only way to recover is to kill Dashcode and use a backup copy.


Michi.


Thanks for the warnings. I think I've seen most of those problems ;-)


a) This happened fairly regularly with the 'old' version. But strangely some of the those bad project files would come good after quitting Dashcode. I would always need to open the project file from within Dashcode. No success double-clicking on a project file.


b) Canvas with missing elements. Yep. Close the project, quit Dashcode and restart. Sometime a couple of times.


c) I have copies of projects now. In multiple places. For the first few projects I only had one or two copies. I only have two or three types of widgets so I've a number of versions of each type now.


d) That's way I immediately try to save the project file when first opening it otherwise it was useless to continue. Close, quite, restart usually worked.


It is a challenge but part of the 'fun' of programming. :-)


Thanks for your insight. David

Check boxes in ibook author?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.