{"id":305,"date":"2017-09-09T23:07:06","date_gmt":"2017-09-09T21:07:06","guid":{"rendered":"https:\/\/asdw.de\/?p=305"},"modified":"2017-09-09T23:09:10","modified_gmt":"2017-09-09T21:09:10","slug":"toggle-slider-as-select-or-radio-buttons-in-scriptcase","status":"publish","type":"post","link":"https:\/\/asdw.de\/en\/toggle-slider-as-select-or-radio-buttons-in-scriptcase\/","title":{"rendered":"Toggle slider as select- or radio-buttons in Scriptcase"},"content":{"rendered":"<h2>Show graphical on\/off-switches in select or radio-elements of Scriptcase Forms<\/h2>\n<p>Usually Scriptcase Form-Applications use the HTML elements to show Select- and Radio-elements:<\/p>\n<p><a href=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-296\" src=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old.png\" alt=\"select or radio buttons standard\" width=\"420\" height=\"69\" srcset=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old.png 420w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old-300x49.png 300w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old-100x16.png 100w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old-150x25.png 150w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-old-200x33.png 200w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/a><\/p>\n<p>This can be changed by using a CSS and a &#8216;replace&#8217;-code:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-294 size-full\" src=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new.png\" alt=\"select or radio buttons new\" width=\"514\" height=\"74\" srcset=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new.png 514w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new-300x43.png 300w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new-100x14.png 100w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new-150x22.png 150w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new-200x29.png 200w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-new-450x65.png 450w\" sizes=\"(max-width: 514px) 100vw, 514px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>1. Load the new CSS definition in the onLoad-Event of the form application.<\/h3>\n<p>This defines the &#8216;look&#8217; and the &#8216;animation&#8217; of the new &#8216;sliders&#8217;:<\/p>\n<pre class=\"lang:php decode:true\" title=\"CSS definition of the slider\">?&gt;\r\n&lt;style&gt;\r\n.scFormLabelOdd{\r\n font-size: 19px;   \/\/ label\r\n}\r\n.scFormDataFontOdd{\r\n font-size: 19px;   \/\/ label\r\n}\r\n.slider-label {\r\n  position: relative;\r\n  display: inline-block;\r\n  width: 50px;\t\t\/\/ background of the slider\r\n  height: 20px;\r\n}\r\n.slider-label input {display:none;}\r\n.slider {\r\n  position: absolute;\r\n  cursor: pointer;\r\n  top: 0;\r\n  left: 0;\r\n  right: 0;\r\n  bottom: 0;\r\n  background-color: #ccc;\r\n  -webkit-transition: .4s;\r\n  transition: .4s;\r\n}\r\n.slider:before {\r\n  position: absolute;\r\n  content: \"\";\r\n  height: 19px;\t\t\/\/ round button of the slider\r\n  width: 19px;\t\t\/\/       \"-\"\r\n  left: 1px;\r\n  bottom: 1px;\r\n  background-color: white;\r\n  -webkit-transition: .4s;\r\n  transition: .4s;\r\n}\r\ninput:checked + .slider {\r\n  background-color: #2196F3;\r\n}\r\ninput:focus + .slider {\r\n  box-shadow: 0 0 1px #2196F3;\r\n}\r\ninput:checked + .slider:before {\r\n  -webkit-transform: translateX(25px);\r\n  -ms-transform: translateX(25px);\r\n  transform: translateX(25px);\r\n}\r\n\/* Rounded sliders *\/\r\n.slider.round {\r\n  border-radius: 34px;\r\n  margin-right: 4px;\t\r\n}\r\n.slider.round:before {\r\n  border-radius: 50%;\r\n}\r\n&lt;\/style&gt;\r\n&lt;?php<\/pre>\n<p>These is HTMP\/CSS code. Therefore the PHP-code of the Scriptcase-form has to be stopped with\u00a0\u00a0<span class=\"lang:php decode:true crayon-inline \">?&gt;<\/span>\u00a0 and started again \u00a0<span class=\"lang:php decode:true crayon-inline \">&lt;?php<\/span>\u00a0after the new code.<\/p>\n<p>This definiton was used in a presentation done by Marcia\u00a0(<a href=\"http:\/\/scriptcase.net\" target=\"_blank\" rel=\"noopener\">Scriptcase<\/a>) on Youtube\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=qoEDNKAxa_Y\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=qoEDNKAxa_Y<\/a><br \/>\nAny other CSS-definition can be used. For example &#8211; this is a website with a generation for such a definition:\u00a0<span class=\"lang:php decode:true crayon-inline \">https:\/\/proto.io\/freebies\/onoff\/<\/span><br \/>\nAnd there are much more on the Web&#8230;<\/p>\n<p><em>If you find nice ones, please leave the URLs as comment to this article \ud83d\ude09<\/p>\n<p><\/em><\/p>\n<h3>2. The form has to have some Select- and\/or Radio-Fields:<\/h3>\n<p>This sample uses:<\/p>\n<div id=\"attachment_298\" style=\"width: 160px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-radio.png\" target=\"_blank\" rel=\"noopener\"><img aria-describedby=\"caption-attachment-298\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-298 size-thumbnail\" src=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-radio-150x150.png\" alt=\"Definition Radio Element\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-298\" class=\"wp-caption-text\">Click to enlarge<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_300\" style=\"width: 160px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-select.png\" target=\"_blank\" rel=\"noopener\"><img aria-describedby=\"caption-attachment-300\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-300 size-thumbnail\" src=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-select-150x150.png\" alt=\"Definition Radio Element\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-300\" class=\"wp-caption-text\">Click to enlarge<\/p><\/div>\n<p>&nbsp;<\/p>\n<h3>3. Define, which fields (select\/radio) will show the new form:<\/h3>\n<p>To do this, you can add a jQuery code in the onLoad-event of the form.<\/p>\n<p>Sample 1 &#8211; ALL select and radio-fields:<\/p>\n<pre class=\"lang:php decode:true\" title=\"replace ALL Select\/Radio Forms\">&lt;script&gt;\r\n$(document).ready(function(){\r\n\t\r\n\t$(\"input:checkbox,:radio\").each(function(i) { \r\n\t\tconsole.log('index:' + i + this.value); \r\n\t\t$(this).replaceWith('&lt;label class=\"slider-label\"&gt; &lt;input  onclick = \"\" type=\"' + this.type + '\"  name=\"' + this.name + '\" value = \"' + this.value + '\"&gt; &lt;span class=\"slider round\"&gt;&lt;\/span&gt; &lt;\/label&gt;');\r\n\t\t} );\r\n\r\n});\r\n&lt;\/script&gt;<\/pre>\n<p>Sample 2 &#8211; Only the select fields on the form:<\/p>\n<pre class=\"lang:php decode:true\" title=\"Replace select Elements only\">&lt;script&gt;\r\n$(document).ready(function(){\r\n\r\n\t$(\"input:checkbox\").each(function(i) { \r\n\t\tconsole.log('index:' + i + this.value); \r\n\t\t$(this).replaceWith('&lt;label class=\"slider-label\"&gt; &lt;input  onclick = \"\" type=\"' + this.type + '\"  name=\"' + this.name + '\" value = \"' + this.value + '\"&gt; &lt;span class=\"slider round\"&gt;&lt;\/span&gt; &lt;\/label&gt;');\r\n\t\t} );\r\n\r\n});\r\n&lt;\/script&gt;<\/pre>\n<p>Sample 3 &#8211; Only the radio field with the name radio_1:<\/p>\n<pre class=\"lang:php decode:true\" title=\"Replace only Radio Element with name radio_1\">&lt;script&gt;\r\n$(document).ready(function(){\r\n\r\n\t$(\"input[name*='radio_1']\").each(function(i) { \r\n\t\tconsole.log('index:' + i + this.value); \r\n\t\t$(this).replaceWith('&lt;label class=\"switch\"&gt; &lt;input  onclick = \"\" type=\"radio\"  name=\"radio_1\" value = \"' + this.value + '\"&gt; &lt;span class=\"slider round\"&gt;&lt;\/span&gt; &lt;\/label&gt;');\r\n\t\t} );\r\n\t\/\/ oder k\u00fcrzer:\r\n\t$(\"input[name*='radio_1']\").replaceWith('&lt;label class=\"switch\"&gt; &lt;input  onclick = \"\" type=\"radio\"  name=\"radio_1\" value = \"123\"&gt; &lt;span class=\"slider round\"&gt;&lt;\/span&gt; &lt;\/label&gt;');\r\n\r\n});\r\n&lt;\/script&gt;\r\n<\/pre>\n<p><strong>Hint:<\/strong> This is JQuery-code, which has to be enclosed by\u00a0<span class=\"lang:php decode:true crayon-inline\">?&gt;<\/span>\u00a0 and\u00a0<span class=\"lang:php decode:true crayon-inline\">&lt;?php<\/span>\u00a0 too.<\/p>\n<p><strong>Hint:<\/strong> Scriptcase contains the jQuery libraries in development and deployed applications. Thus the jQuery libraries have not to be loaded.<\/p>\n<p>Such a form could look like:<\/p>\n<p><a href=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-302\" src=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form.png\" alt=\"Scriptcase Form with toggle slider as select or radio\" width=\"573\" height=\"391\" srcset=\"https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form.png 573w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form-300x205.png 300w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form-100x68.png 100w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form-150x102.png 150w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form-200x136.png 200w, https:\/\/asdw.de\/wp-content\/uploads\/2017\/09\/toggle-slider-form-450x307.png 450w\" sizes=\"(max-width: 573px) 100vw, 573px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Show graphical on\/off-switches in select or radio-elements of Scriptcase Forms Usually Scriptcase Form-Applications use the HTML elements to show Select- and Radio-elements: This can be changed by using a CSS and a &#8216;replace&#8217;-code: &nbsp; 1. Load the new CSS definition<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"https:\/\/asdw.de\/en\/toggle-slider-as-select-or-radio-buttons-in-scriptcase\/\">Read more &#8250;<\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":2,"featured_media":303,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[55],"tags":[96,95,50,94,92],"_links":{"self":[{"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/posts\/305"}],"collection":[{"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/comments?post=305"}],"version-history":[{"count":3,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/posts\/305\/revisions\/308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/media\/303"}],"wp:attachment":[{"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asdw.de\/en\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}