DEV Community

Peter + AI
Peter + AI

Posted on

📝 Understanding Uniface $bold Function: Simple Text Styling in Forms

â„šī¸ This blog post was created with AI assistance to help explain Uniface development concepts clearly.

đŸŽ¯ What is the $bold Function?

The $bold function in Uniface 10.4 is a simple but powerful tool that applies bold character styling to text strings. Think of it like making text bold in a word processor, but specifically for Uniface form components.

🔧 How Does It Work?

The function has a straightforward syntax:

$bold ( String )
Enter fullscreen mode Exit fullscreen mode

Where:

  • String: The text you want to make bold
  • Return Value: The same text with bold formatting applied

âš ī¸ Important Things to Know

  • 🏠 Form Components Only: This function only works in Form components, not other types of Uniface components
  • đŸ‘ī¸ Visual Display: The bold effect is only visible in displayed unifields (user interface fields)
  • 🎨 Character Attribute: It applies a character attribute, which means it affects how the text looks, not the text content itself

📖 Key Terms Explained

  • Unifield: A field in a Uniface form that displays data to users
  • Character Attribute: Formatting that changes how text appears (like bold, italic, underline)
  • ProcScript: The programming language used in Uniface for application logic
  • Trigger: Code that runs when specific events happen (like clicking a field)

💡 Practical Example

Here's a real-world example that makes field labels bold when users click on them:

trigger loseFocus 
    putItem/id $labelProperties($fieldname), "text", 
    $stripAttributes($valuePart($labelProperties($fieldname)))
end

trigger getFocus
    putItem/id $labelProperties($fieldname), "text", 
    $bold($valuePart($labelProperties($fieldname)))
end
Enter fullscreen mode Exit fullscreen mode

🔍 What This Example Does:

  1. getFocus trigger: When a user clicks on a field, the label becomes bold
  2. loseFocus trigger: When the user clicks away, the label returns to normal text
  3. $stripAttributes: Removes formatting (like bold) from text
  4. $labelProperties: Gets or sets properties of field labels

đŸŽ¯ When to Use $bold

  • đŸ–ąī¸ Interactive Forms: Highlight active fields or important information
  • âš ī¸ Error Messages: Make warning text stand out
  • 📋 Dynamic Labels: Change label appearance based on user actions
  • 🎨 Visual Feedback: Provide immediate visual response to user interactions

🔗 Related Functions

The $bold function works well with other text formatting functions:

  • $stripAttributes: Removes all formatting from text
  • $italic: Applies italic formatting
  • $underline: Applies underline formatting

✅ Best Practices

  • đŸŽ¯ Use bold sparingly to maintain visual hierarchy
  • 🔄 Always provide a way to remove bold formatting when it's no longer needed
  • 📱 Test bold text appearance across different screen sizes and resolutions
  • â™ŋ Consider accessibility - ensure bold text maintains good contrast

🎉 Conclusion

The $bold function is a simple yet effective tool for enhancing user interfaces in Uniface applications. By understanding when and how to use it, you can create more engaging and user-friendly forms that provide clear visual feedback. Remember to use it thoughtfully and always test your formatting in the actual application environment! 🚀


💡 _Have you used the $bold function in your Uniface projects? Share your experiences and tips in the comments below!_face $bold Function: Simple Text Styling in Forms

Top comments (0)