coding standards – Opinions on Negative Naming in Forms

Is it ever acceptable to use a negative name for a boolean variable? For example, I have a few user forms that have a checkbox for “N/A” or “Not Assessed”. These aren’t going to be used as a part of any query, nor are they going to be used in any complex application logic. These checkboxes exist solely so clinicians can acknowledge that they know they didn’t fill something out.

I normally wouldn’t drag a work disagreement onto the web, but I feel like I unfortunately need backup on this one. I work with a contractor that often gets deferential treatment because of how much more his time costs. He has decided to go through and mark all of my instances of “isNotApplicable” and “isNotAssessed” as “bad code needing revision”. I explained the scenario to him only to be informed that negative variable names are always bad, and that if he sees it, he will change it. It doesn’t sound like the biggest deal now, but there are a few forms coming up where changing a single word could cost people things like Medicare funding, and forcing the form to use the opposite of the stored value seems like a much bigger recipe for problems.

There are countless blogs and guides talking about how bad negative boolean naming is, but many of them acknowledge that there are exceptions. Unfortunately there isn’t much out there to help argue that maintaining clarity between the UI and the model is more important than preventing the possibility of double negatives appearing in your code, maybe because it seems too obvious, or maybe because I am just wrong. The strongest example I could find was a line from the Dart docs. Dart: Prefer Positive Names

8 – How do I detect whether any contact forms have been created?

Context: On my Drupal 8 site I’m trying to add in a new section containing a view that lists out all forms. The user can then click on one of the form and it launches a download of all the messages sent through that form. However that section should only be visible if the user has created at least 1 form.

What I’ve tried: So far what I’ve discovered is that the contact forms are stored in the config table in the database, so I could theoretically run a query like “SELECT 1 FROM config WHERE name LIKE ‘%contact.form%'” or whatever the equivalent in D8 is. However, it seems like there has to be a quicker way to return either the presence of contact forms or the contact forms themselves programmatically.

Final question: How can I return either the contact forms themselves or at least a boolean representing the presence of contact forms programmatically?

forms – Drupal 8: Ajax error when trying to add another paragraph

Drupal 8.9 and paragraph 8.x-1.11

I have a paragraph type:

contact_information

  • field_phone_number (telephone from core)
  • field_type_of_phone (text_plain)

I have a custom module. In this custom module I am creating a form_alter on /user/register

I have:

function telephone_alter_form_user_register_form_alter(&$form, $form_state, $form_id ){
  $form('#validate')() = 'telephone_alter_test_validate';
  //$form('field_phone')('widget')('#element_validate')() = 'telephone_alter_test_validate';
}

function telephone_alter_test_validate($form, &$form_state) {
 kint::dump(form_state);
}

The validation works, prints out debugging. However, when I try to add another element, it does nothing.

the error displayed is:

({"command":"insert","method":"prepend","selector":null,"data":"u003Cdiv data-drupal-messagesu003En  u003Cdiv class=u0022messages__wrapperu0022u003En u003Cdiv class=u0022alert alert-danger alert-dismissibleu0022 role=u0022alertu0022 aria-label=u0022Error messageu0022u003En u003Cbutton type=u0022buttonu0022 role=u0022buttonu0022 class=u0022closeu0022 data-dismiss=u0022alertu0022 aria-label=u0022Closeu0022u003Eu003Cspan aria-hidden=u0022trueu0022u003Eu0026times;u003C/spanu003Eu003C/buttonu003En u003Ch2 class=u0022sr-onlyu0022u003EError messageu003C/h2u003En u003Cpu003EAn unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (40 MB) that this server supports.u003C/pu003En u003C/divu003En    u003C/divu003Enu003C/divu003En","settings":null})

Any help is great! Thank you! I can provide more info if needed

forms – Best pattern to tackle optional configurations

I’m working on a project that creates organizations managed by a single user.

Besides the required data (eg: organization name) there are a number of optional configurations:

  • Logo
  • Website URL
  • Social media accounts
  • Other settings and preferences

I’m wondering if there is any research on the best approach to tackle these optional configurations.

Here are the possible ways I see to tackle this:

1) Force users to see the optional fields

I could add more fields to the main form or add a second step with the fields marked as optional. This seems like the most annoying option for users as it has the bigger cognitive load.

2) Let users decide if they want to fill those now or later

Instead of showing all the fields I could ask users if they’d like to fill more details now or later. This seems less annoying but OTOH users may not understand the implications and I’m forcing them to make decision.

3) Simply ignore optional settings and show some tips afterwards

Just force users to fill the minimum required fields and leave the optional settings with their default value. Once the organization has been created I can show something in the UI to let them know they can fill in the additional configurations.

cognito forms – Is there a way to only allow visitors to select specific days of the week from the Date field?

I have a form for booking testing appointments. Testing dates are limited to Thursdays, Saturdays, and Sundays from 10am-2pm. I would like the ability to only allow visitors to select those days from the calendar in the Date field. If possible, I would also like the ability to only allow visitors to select 10am-2pm from the Time field. I have searched for a solution but have been unable to find any for my dilemma. Thank you.

forms – How does the Drupal Module for FormAssembly work?

What type of embed does the FormAssembly Module https://www.drupal.org/node/2569059 create on a Drupal webpage? Is this an iframe embed? Or is it more of a “native” embed.

FormAssembly is a form builder and this module was built by Drupal users. I’m looking to understand how it works, so we can see if we can use this module or if we need to find another way to embed our form onto our website.

Thank you!

google forms – Script Execution succeeds but reports failure

I’m running this script on a Google Form responses sheet:

function autoSort(sheet) {
  var SORT_COLUMN_INDEX = 10;
  var ASCENDING = true;
  var NUMBER_OF_HEADER_ROWS = 1;
  var range = sheet.getDataRange();
  if (NUMBER_OF_HEADER_ROWS > 0) {
    range = range.offset(NUMBER_OF_HEADER_ROWS, 0);
  }
  range.sort( {
    column: SORT_COLUMN_INDEX,
    ascending: ASCENDING
  } );
}

function onOpen(event) {
  autoSort(event.source);
  }

I set a trigger to run the script whenever the sheet is opened. The script is functioning properly, but I’m getting emails telling me it failed. In the Execution list the error reported is:

TypeError: sheet.getDataRange is not a function
    at autoSort(Autosort:5:21)

I used the same script in another very similar form and I didn’t have these errors. Can anyone illuminate me what is wrong? Why is a failure being reported while the script works as requested?

forms – Custom select component with filtering

Custom select components are seen everywhere these days due to the limitations of the native HTML select element. Ignoring the virtues (or lack thereof) of select components (c.f. https://gerireid.com/forms.html#select), I have a question on the UX of “filterable” custom select components.

Consider this example from the popular react-select library:

short gif demonstrating the use of a filterable react-select component

As you can see, typing in the input filters the list of options. If the user unfocussed the input (e.g. by clicking outside, like I did), the value of the input is reverted to what it was before the user started typing. If the user selects one of the options (by clicking or by pressing “Enter”), the value of the input changes to the value of that option.

It seems to be that this behaviour could be confusing to users. Typing in a field that looks very much like a text input should behave like a text input, but here leaving the field without having selected an option snaps the value back to what it was before! Even worse, if the user types a value that is a valid option, e.g. Ocean, it will also snap back to the last value unless they explicitly select the Ocean option from the filtered list.

Now consider Stripe’s implementation:

short gif demonstrating the use of Stripe's filterable select component

Instead of using the input itself as a search filter, they use another input at the top of the list of options. When the user clicks on the select component the focus switches to the search input. They can filter options and select one. If the component loses focus (e.g. the user click s outside of it, like I did), the dropdown closes, leaving the value of the select unchanged.

This seems a lot more intuitive to me. There isn’t the surprising behaviour of the select’s value “snapping back”. It stays the same until you select an option, and filtering is done through a separate field.

Now I have two questions:

  1. What do you think? Do you agree that Stripe’s implementation provides a (significantly) better user experience? And if you disagree, why?
  2. Do you have any references (either user research or “authoritative” sources) that mention this specific problem? My intuition tells me that react-select’s implementation provides poor user experience, but… my intuition is very far from authoritative.

Thanks!

forms – How do you add a input and a select field with webforms?

I would like to add a select element that has an input field attached, so the user can input a value from the list without having to scroll through hundreds of options. Is this possible to do with the module webforms? I have researched it and the only thing I can find is the chosen module but I have no idea how the two integrate, and alot of people say it is incompatible in some browsers. Thank you for your help.

gui – Unity: How to work with forms

Usually I just create a class for that specific form. Using your example login dialog above, that might look something like this:

(System.Serializable) public class LoginDialogEvent : UnityEvent<string, string> {}

public class LoginDialog : MonoBehaviour {
    (SerializeField) private InputField username;
    (SerializeField) private InputField password;
    (SerializeField) private LoginDialogEvent submitEvent = new LoginDialogEvent();
    public LoginDialogEvent SubmitEvent => submitEvent;

    public string Username { get => username.text; set => username.text = value; }
    public string Password { get => password.text; set => password.text = value; }

    void Start() {
        Assert.IsNotNull(username);
        Assert.IsNotNull(password);
    }

    //call this from the click event on the button in the inspector
    public void Submit() {
        submitEvent.Invoke(Username, Password);
    }
}

Then you’d use it something like this:

LoginDialog dialog = Instantiate(loginDialogPrefab);
dialog.SubmitEvent.AddListener(OnLoginDialogSubmit);
void OnLoginDialogSubmit(string username, string password) {
    loginService.Login(username, password);
}

If your application has a limited number of forms, it doesn’t take very long to write up the custom classes for them. If you’re going to have a huge number of forms, highly complex forms, or forms that are dynamically generated at runtime, you may need something more sophisticated.