{"id":554,"date":"2020-08-21T14:18:31","date_gmt":"2020-08-21T14:18:31","guid":{"rendered":"https:\/\/jmrowe.com\/blog\/?p=554"},"modified":"2020-08-24T00:29:51","modified_gmt":"2020-08-24T00:29:51","slug":"adding-on-focus-animations-to-a-fluent-form","status":"publish","type":"post","link":"https:\/\/jmrowe.com\/blog\/adding-on-focus-animations-to-a-fluent-form\/","title":{"rendered":"Adding on focus animations to a Fluent Form"},"content":{"rendered":"<p><a href=\"https:\/\/wpmanageninja.com\/downloads\/fluentform-pro-add-on\/\" target=\"_blank\" rel=\"noopener noreferrer\">Fluent Forms<\/a> is a popular WordPress plugin that allows you to make forms easily. One thing I didn&#8217;t like is that there is no onFocus options for animations etc. With inspiration from a different post about hyper link hover animations (\u00a0<a href=\"https:\/\/www.peeayecreative.com\/custom-divi-menu-effects-free-download\/\" target=\"_blank\" rel=\"noopener noreferrer\">found here<\/a> ) for Divi menu modules, I added on focus animation for my Fluent Form. I created this small tutorial to show how I did it.<\/p>\n<p>Here is an example of what the outcome looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-557 size-full\" src=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2020\/08\/animated-focus.gif\" alt=\"Fluent Forms animated on focus \" width=\"720\" height=\"714\" \/><\/p>\n<p>To do this, you first have to add the class &#8220;animated_form_element&#8221; under the Advanced Options for each of the text\/textarea&#8217;\u00a0 &#8220;Element Class&#8221; field such as below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-559\" src=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2020\/08\/add-class-to-element-for-animation.png\" alt=\"\" width=\"490\" height=\"470\" srcset=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2020\/08\/add-class-to-element-for-animation.png 490w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2020\/08\/add-class-to-element-for-animation-300x288.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Next, we need to add some custom css and javascript to our form. We add it by going to the form&#8217;s\u00a0 &#8220;Settings &amp; Integrations tab -&gt; Custom CSS\/JS&#8221; section.<\/p>\n<p>For the CSS, it really depends on the look you are going for but for this example I wanted a bottom border to be shown on the input\/textarea field regardless if it has focus or not. I also removed the default border radius on the input field as well. Here is the customer css to accomplish those things.<\/p>\n<pre class=\"lang:default decode:true\">.fluentform .ff-el-form-control{\r\n   border-top:0px!important;\r\n   border-left:0px!important;\r\n   border-right:0px!important;\r\n   border-bottom:rgb(116, 175, 205) solid 1px!important;\r\n   border-radius:0px!important;\r\n}<\/pre>\n<p>I use !important to be sure it overrides Fluent Forms default styles.<\/p>\n<p>Next, let&#8217;s add the styles needed for the actual animation itself as well as modifying how the &#8220;This field is required.&#8221; is shown:<\/p>\n<pre class=\"lang:default decode:true\">.animatedStyleName {\r\n\tposition: relative;\r\n\toverflow: hidden;\r\n\ttransition: all 0.3s;\r\n\t-webkit-transition: all 0.3s;\r\n\t-moz-transition: all 0.3s;\r\n\t-o-transition: all 0.3s;\r\n}\r\n\r\n.animatedStyleName::before {\r\n\tcontent: \"\";\r\n\tposition: absolute;\r\n\tz-index: 2;\r\n\tleft: 0;\r\n\tright: 100%;\r\n\tbottom: 0;\r\n\tbackground: rgb(116, 175, 205);\r\n\theight: 2px;\r\n\t-webkit-transition: all 0.3s ease-out;\r\n\t-moz-transition: all 0.3s ease-out;\r\n\t-o-transition: all 0.3s ease-out;\r\n}\r\n\r\n.activate::before {\r\n\tright: 0;\r\n}\r\n\r\n.fluentform .ff-el-form-control {\r\n\tborder-radius: 0px!important;\r\n}\r\n\r\n.fluentform .ff-el-is-error .text-danger {\r\n\tposition: absolute;\r\n\tbottom: 5px;\r\n}<\/pre>\n<p>The error message for &#8220;This field is required&#8221; aka .text-danger is made switched to absolute\u00a0 positioning and in this case has been set 5px from the bottom of the input fields container. Really, this could be different based on how you want the field to show on the form. You could use top instead for example. However, the .text-danger must be made absolute as we need it out of the document flow so it won&#8217;t create visual bugs with extra space in between the inputs border bottom\u00a0 and the border bottom that is used to create the animation.<\/p>\n<p>Finally, we need to add some custom javascript to the form as well:<\/p>\n<pre class=\"lang:default decode:true \">jQuery(\".animated_form_element\").parent().addClass(\"animatedStyleName\");\r\njQuery(\".animated_form_element\").each(function () {\r\n\tif (jQuery(this).val()) {\r\n\t\tjQuery(this).parent().addClass(\"activate\");\r\n\t}\r\n});\r\njQuery(\".animated_form_element\").focus(function () {\r\n\tjQuery(this).parent().addClass(\"activate\");\r\n\tjQuery(this).next('.text-danger').css(\"display\", \"none\");\r\n});\r\n \r\n \r\njQuery(\".animated_form_element\").blur(function () {\r\n\tif (!jQuery(this).val()) {\r\n\t\tjQuery(this).parent().removeClass(\"activate\");\r\n\t}\r\n});\r\n \r\njQuery(\".ff-el-input--content\").click(function () {\r\n\tjQuery(this).children('.text-danger').css(\"display\", \"none\");\r\n\tjQuery(this).children('.animated_form_element').focus();\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>And that&#8217;s it for this example really.<\/p>\n<p>You may notice I named the actual animation class name &#8220;animatedStyleName&#8221; which is generic. I did this because really you could take many of the different animations listed in the divi-menu-effects.css you can download from <a href=\"https:\/\/www.peeayecreative.com\/custom-divi-menu-effects-free-download\/\" target=\"_blank\" rel=\"noopener noreferrer\">this site<\/a> and replace the rules of animatedStyleName to do different types of animations. You have to subscribe to his newsletter in order to get the previously mentioned .css file that has the different animations. Some of the animation examples on that site require more work than what I described but I plan on writing an extension of this tutorial if it seems people might want it.<\/p>\n<p>Can download the Fluent Form export example <a href=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/form-exports\/fluentform-export-forms-1-23-08-2020.json\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> . You may have to right click -&gt; &#8220;save link as&#8221; for it to work.<\/p>\n<p>Live example:<\/p>\n<div class='fluentform ff-default fluentform_wrapper_4 ffs_default_wrap'><form data-form_id=\"4\" id=\"fluentform_4\" class=\"frm-fluent-form fluent_form_4 ff-el-form-top ff_form_instance_4_1 ff-form-loading form_test_class ffs_default\" data-form_instance=\"ff_form_instance_4_1\" method=\"POST\" ><fieldset  style=\"border: none!important;margin: 0!important;padding: 0!important;background-color: transparent!important;box-shadow: none!important;outline: none!important; min-inline-size: 100%;\">\n                    <legend class=\"ff_screen_reader_title\" style=\"display: block; margin: 0!important;padding: 0!important;height: 0!important;text-indent: -999999px;width: 0!important;overflow:hidden;\">contactus<\/legend><input type='hidden' name='__fluent_form_embded_post_id' value='554' \/><input type=\"hidden\" id=\"_fluentform_4_fluentformnonce\" name=\"_fluentform_4_fluentformnonce\" value=\"db28c55521\" \/><input type=\"hidden\" name=\"_wp_http_referer\" value=\"\/blog\/wp-json\/wp\/v2\/posts\/554\" \/><div data-name=\"ff_cn_id_1\"  class='ff-t-container ff-column-container ff_columns_total_2 '><div class='ff-t-cell ff-t-column-1' style='flex-basis: 50%;'><div class='ff-el-group container-test'><div class=\"ff-el-input--label ff-el-is-required asterisk-right\"><label for='ff_4_company_name' id='label_ff_4_company_name' >Company Name<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"company_name\" class=\"ff-el-form-control animated_form_element\" data-name=\"company_name\" id=\"ff_4_company_name\"  aria-invalid=\"false\" aria-required=true><\/div><\/div><\/div><div class='ff-t-cell ff-t-column-2' style='flex-basis: 50%;'><div class='ff-el-group'><div class=\"ff-el-input--label ff-el-is-required asterisk-right\"><label for='ff_4_contact_name' id='label_ff_4_contact_name' >Contact Name<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"contact_name\" class=\"ff-el-form-control animated_form_element\" data-name=\"contact_name\" id=\"ff_4_contact_name\"  aria-invalid=\"false\" aria-required=true><\/div><\/div><\/div><\/div><div data-name=\"ff_cn_id_2\"  class='ff-t-container ff-column-container ff_columns_total_2 '><div class='ff-t-cell ff-t-column-1' style='flex-basis: 50%;'><div class='ff-el-group'><div class=\"ff-el-input--label ff-el-is-required asterisk-right\"><label for='ff_4_email' id='label_ff_4_email' aria-label=\"Email\">Email<\/label><\/div><div class='ff-el-input--content'><input type=\"email\" name=\"email\" id=\"ff_4_email\" class=\"ff-el-form-control animated_form_element\" data-name=\"email\"  aria-invalid=\"false\" aria-required=true><\/div><\/div><\/div><div class='ff-t-cell ff-t-column-2' style='flex-basis: 50%;'><div class='ff-el-group'><div class=\"ff-el-input--label ff-el-is-required asterisk-right\"><label for='ff_4_phone' id='label_ff_4_phone' aria-label=\"Phone\">Phone<\/label><\/div><div class='ff-el-input--content'><input name=\"phone\" class=\"ff-el-form-control ff-el-phone animated_form_element\" type=\"tel\" data-name=\"phone\" id=\"ff_4_phone\" inputmode=\"tel\"  aria-invalid='false' aria-required=true><\/div><\/div><\/div><\/div><div data-name=\"ff_cn_id_3\"  class='ff-t-container ff-column-container ff_columns_total_1 '><div class='ff-t-cell ff-t-column-1' style='flex-basis: 100%;'><div class='ff-el-group'><div class=\"ff-el-input--label asterisk-right\"><label for='ff_4_address' id='label_ff_4_address' aria-label=\"Address\">Address<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"address\" class=\"ff-el-form-control animated_form_element\" data-name=\"address\" id=\"ff_4_address\"  aria-invalid=\"false\" aria-required=false><\/div><\/div><\/div><\/div><div data-name=\"ff_cn_id_4\"  class='ff-t-container ff-column-container ff_columns_total_3 '><div class='ff-t-cell ff-t-column-1' style='flex-basis: 34%;'><div class='ff-el-group'><div class=\"ff-el-input--label asterisk-right\"><label for='ff_4_city' id='label_ff_4_city' aria-label=\"City\">City<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"city\" class=\"ff-el-form-control animated_form_element\" data-name=\"city\" id=\"ff_4_city\"  aria-invalid=\"false\" aria-required=false><\/div><\/div><\/div><div class='ff-t-cell ff-t-column-2' style='flex-basis: 34%;'><div class='ff-el-group'><div class=\"ff-el-input--label asterisk-right\"><label for='ff_4_state' id='label_ff_4_state' aria-label=\"State\">State<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"state\" class=\"ff-el-form-control animated_form_element\" data-name=\"state\" id=\"ff_4_state\"  aria-invalid=\"false\" aria-required=false><\/div><\/div><\/div><div class='ff-t-cell ff-t-column-3' style='flex-basis: 34%;'><div class='ff-el-group'><div class=\"ff-el-input--label asterisk-right\"><label for='ff_4_zip_code' id='label_ff_4_zip_code' aria-label=\"Zip Code\">Zip Code<\/label><\/div><div class='ff-el-input--content'><input type=\"text\" name=\"zip_code\" class=\"ff-el-form-control animated_form_element\" data-name=\"zip_code\" id=\"ff_4_zip_code\"  aria-invalid=\"false\" aria-required=false><\/div><\/div><\/div><\/div><div class='ff-el-group'><div class=\"ff-el-input--label ff-el-is-required asterisk-right\"><label for='ff_4_message' id='label_ff_4_message' aria-label=\"Message\">Message<\/label><\/div><div class='ff-el-input--content'><textarea aria-required=\"true\" aria-labelledby=\"label_ff_4_message\" name=\"message\" id=\"ff_4_message\" class=\"ff-el-form-control animated_form_element\" rows=\"6\" cols=\"2\" data-name=\"message\" ><\/textarea><\/div><\/div><div class='ff-el-group ff-text-left ff_submit_btn_wrapper'><button type=\"submit\" class=\"ff-btn ff-btn-submit ff-btn-md ff_btn_style\"  aria-label=\"Send\">Send<\/button><\/div><\/fieldset><\/form><div id='fluentform_4_errors' class='ff-errors-in-stack ff_form_instance_4_1 ff-form-loading_errors ff_form_instance_4_1_errors'><\/div><\/div>            <script type=\"text\/javascript\">\n                window.fluent_form_ff_form_instance_4_1 = {\"id\":\"4\",\"ajaxUrl\":\"https:\\\/\\\/jmrowe.com\\\/blog\\\/wp-admin\\\/admin-ajax.php\",\"settings\":{\"layout\":{\"labelPlacement\":\"top\",\"helpMessagePlacement\":\"with_label\",\"errorMessagePlacement\":\"inline\",\"asteriskPlacement\":\"asterisk-right\"},\"restrictions\":{\"denyEmptySubmission\":{\"enabled\":false}}},\"form_instance\":\"ff_form_instance_4_1\",\"form_id_selector\":\"fluentform_4\",\"rules\":{\"company_name\":{\"required\":{\"value\":true,\"message\":\"This field is required\"}},\"contact_name\":{\"required\":{\"value\":true,\"message\":\"This field is required\"}},\"email\":{\"required\":{\"value\":true,\"message\":\"This field is required\"},\"email\":{\"value\":true,\"message\":\"This field must contain a valid email\"}},\"phone\":{\"required\":{\"value\":true,\"message\":\"This field is required\"},\"valid_phone_number\":{\"value\":false,\"message\":\"Phone number is not valid\"}},\"address\":{\"required\":{\"value\":false,\"message\":\"This field is required\"}},\"city\":{\"required\":{\"value\":false,\"message\":\"This field is required\"}},\"state\":{\"required\":{\"value\":false,\"message\":\"This field is required\"}},\"zip_code\":{\"required\":{\"value\":false,\"message\":\"This field is required\"}},\"message\":{\"required\":{\"value\":true,\"message\":\"This field is required\"}}},\"debounce_time\":300};\n                            <\/script>\n            \n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fluent Forms is a popular WordPress plugin that allows you to make forms easily. One thing I didn&#8217;t like is that there is no onFocus options for animations etc. With inspiration from a different post about hyper link hover animations (\u00a0found here ) for Divi menu modules, I added on focus animation for my Fluent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11],"tags":[],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-development","category-wordpress"],"_links":{"self":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":14,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/554\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}